Jump to content


This topic is now archived and is closed to further replies.


multiable querys

Recommended Posts

ok i need to sort by 2 different things, its a cellular phone site, so i want it to sort by service and make of phone. right now i got it so it sorts the service. phones.php?service=cingular now i want it so it looks like this phone.php?service=cingular&make=Sony Ericson

Share this post

Link to post
Share on other sites


You didn't need to bump this thread in the first place, someone would eventually get around to it. Considering you only waited a day I was reluctant to help you but since I'm a kind spirited person, I decided to continue with the help.


Have you not read enough on SQL to see that it has an AND operator?


Try this:

$service = addslashes($_GET['service']);
$type = addslashes($_GET['make']);
# I know this isn't completely secure but it's a good start. You can work 
# the rest out.

$get_info = mysql_query("SELECT * FROM cellphones WHERE service = '" . $service . "' AND make = '" . $type . "'") or die ("Error, could not run query. MySQL: " . mysql_error());
# After getting everything working or if you don't run into any problems
# I would remove the or die statement. It is mainly used for only debuggin
# and the user doesn't need to see the structure of your database to know
# what exactly went wrong.

if (mysql_num_rows($get_info) == 0) {
echo 'No results found.';
} else { # Results were found

echo 'Results:<br /><br />
do { # Execute code

echo 'Service: ' . $info['service'] . '<br />
       Make: ' . $info['make'] . '<br />';

} while ($info = mysql_fetch_array($get_info));

} // End else for if (mysql_num_rows($get_info) == 0)


You can always retrieve the rest of the information from your database. I'm not sure if I got the table or fields right but I was just guessing. Fix them if needed.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.