SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: MySQL Query Help
-
May 1, 2006, 19:43 #1
- Join Date
- Jun 2005
- Posts
- 40
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
MySQL Query Help
Hi, is it possible to have a query somthing like this:
select * from members where 'this_row' is less than $this_variable and more than $that_variable and 'this_other_row' is lass than $this_other_variable and more than $that_other_variable
Can somebody please turn this into a real query, or if thats impossible, can you join it up with PHP and so i have somthing that returns the same result.
Cheers,
Sean Mascali
-
May 1, 2006, 19:49 #2
- Join Date
- Aug 2000
- Location
- Philadephia, PA
- Posts
- 20,578
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:$sql = "SELECT * FROM members WHERE col1 < $this_variable AND col2 < $that_variable AND (col3 < $this_other_variable AND col3 > $that_other_variable)";
//
Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
-
May 1, 2006, 20:32 #3
- Join Date
- Jun 2005
- Posts
- 40
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
heres what i have done
Thanks,
I tried to change it a bit and its not working properly, can you help me correct this please.
$query = "SELECT * FROM members WHERE trade LIKE $trimmed AND (user_pc_lat < $maxlat AND user_pc_lat > $minlat) AND (user_pc_lon < $maxlon AND user_pc_lon > $minlon) order by trade";
Thanks,
Sean
-
May 1, 2006, 20:40 #4
- Join Date
- Aug 2000
- Location
- Philadephia, PA
- Posts
- 20,578
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Use single quotes around $trimmed since it's a string type column (as opposed to numeric):
PHP Code:$query = "SELECT * FROM members WHERE trade LIKE '$trimmed' AND (user_pc_lat < $maxlat AND user_pc_lat > $minlat) AND (user_pc_lon < $maxlon AND user_pc_lon > $minlon) order by trade";
PHP Code:$query = "SELECT * FROM members WHERE trade = '$trimmed' AND (user_pc_lat < $maxlat AND user_pc_lat > $minlat) AND (user_pc_lon < $maxlon AND user_pc_lon > $minlon) order by trade";
PHP Code:$query = "SELECT * FROM members WHERE trade LIKE '%$trimmed%' AND (user_pc_lat < $maxlat AND user_pc_lat > $minlat) AND (user_pc_lon < $maxlon AND user_pc_lon > $minlon) order by trade";
PHP Code:$result = mysql_query($query, $connection) or die("An error occurred executing $query: " . mysql_error());
Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
-
May 1, 2006, 21:04 #5
- Join Date
- Jun 2005
- Posts
- 40
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks Dan
Yes it works now, thank you.
Bookmarks