shane85 Posted April 2, 2010 Share Posted April 2, 2010 hey guys question - right now on my page I have it set up to pull info from my db and display the info from my prospect_id column in DESC order. the code I am using is $prospectEntries = mysql_query('SELECT * FROM prospects ORDER BY prospect_id DESC ' . $queryLimit) or trigger_error(mysql_error()); while ($prospectEntry = mysql_fetch_array($prospectEntries)) { print_prospectEntry($prospectEntry); } At the top of my page, I have links: View By: Contact Next Date Added Company Name City now, I know I could achieve this by adjusting my query to view by date_added, company_name etc instead of prospect_id, However, how do I make it so I can have multiple querys in my code so that initially the page displays the way it currently is, by prospect_id, however if someone where to click the link "contact next" it would display by contact_next istead of prospect_id....same for the other links. sorry for the newb quetson - thnx in advance Quote Link to comment https://forums.phpfreaks.com/topic/197392-multiple-querysto-view-by-columns-in-db/ Share on other sites More sharing options...
taquitosensei Posted April 2, 2010 Share Posted April 2, 2010 page.php?orderby=prospect contact, date, company, city etc.. then your sql switch($_GET['orderby']) { case "contact": $orderby="contact_next field"; break; case "date": $orderby="date field"; break; case "company": $orderby="company field"; break; case "city"; $orderby="city field"; break; case default: $orderby="prospect_id"; break; } $sql="select * from prospects ORDER BY ".mysql_real_escape_string($orderby)." DWSC '.$queryLimit; Quote Link to comment https://forums.phpfreaks.com/topic/197392-multiple-querysto-view-by-columns-in-db/#findComment-1036053 Share on other sites More sharing options...
shane85 Posted April 2, 2010 Author Share Posted April 2, 2010 I get this error Parse error: syntax error, unexpected T_DEFAULT for this line case default: Quote Link to comment https://forums.phpfreaks.com/topic/197392-multiple-querysto-view-by-columns-in-db/#findComment-1036064 Share on other sites More sharing options...
shane85 Posted April 2, 2010 Author Share Posted April 2, 2010 I commented out that line and adjusted the code to this but doesnt work...what is wrong??? switch($_GET['orderby']) { case "contact": $orderby="$arrEntry[contact_next]"; break; case "date": $orderby="$arrEntry[tstamp]"; break; case "company": $orderby="$arrEntry[company_name]"; break; case "city"; $orderby="$arrEntry[city]"; break; //case default: //$orderby="prospect_id"; //break; } // Prints all records from Prospect ID //$prospectEntries = mysql_query('SELECT * FROM prospects ORDER BY prospect_id DESC ' . $queryLimit) or trigger_error(mysql_error()); $prospectEntries = mysql_query('SELECT * from prospects ORDER BY ".mysql_real_escape_string($orderby)." DESC '.$queryLimit) or trigger_error(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/197392-multiple-querysto-view-by-columns-in-db/#findComment-1036067 Share on other sites More sharing options...
jcbones Posted April 2, 2010 Share Posted April 2, 2010 I commented out that line and adjusted the code to this but doesnt work...what is wrong??? switch($_GET['orderby']) { case "contact": $orderby="$arrEntry[contact_next]"; break; case "date": $orderby="$arrEntry[tstamp]"; break; case "company": $orderby="$arrEntry[company_name]"; break; case "city"; $orderby="$arrEntry[city]"; break; //case default: //$orderby="prospect_id"; //break; } // Prints all records from Prospect ID //$prospectEntries = mysql_query('SELECT * FROM prospects ORDER BY prospect_id DESC ' . $queryLimit) or trigger_error(mysql_error()); $prospectEntries = mysql_query('SELECT * from prospects ORDER BY ".mysql_real_escape_string($orderby)." DESC '.$queryLimit) or trigger_error(mysql_error()); Change the switch to: switch($_GET['orderby']) { case "contact": $orderby="$arrEntry[contact_next]"; break; case "date": $orderby="$arrEntry[tstamp]"; break; case "company": $orderby="$arrEntry[company_name]"; break; case "city"; $orderby="$arrEntry[city]"; break; default: $orderby="prospect_id"; break; } Quote Link to comment https://forums.phpfreaks.com/topic/197392-multiple-querysto-view-by-columns-in-db/#findComment-1036088 Share on other sites More sharing options...
taquitosensei Posted April 2, 2010 Share Posted April 2, 2010 and you're mixing up your single and double quotes $prospectEntries = mysql_query('SELECT * from prospects ORDER BY ".mysql_real_escape_string($orderby)." DESC '.$queryLimit) or trigger_error(mysql_error()); should be $prospectEntries = mysql_query("SELECT * from prospects ORDER BY ".mysql_real_escape_string($orderby)." DESC ".$queryLimit) or trigger_error(mysql_error()); I commented out that line and adjusted the code to this but doesnt work...what is wrong??? switch($_GET['orderby']) { case "contact": $orderby="$arrEntry[contact_next]"; break; case "date": $orderby="$arrEntry[tstamp]"; break; case "company": $orderby="$arrEntry[company_name]"; break; case "city"; $orderby="$arrEntry[city]"; break; //case default: //$orderby="prospect_id"; //break; } // Prints all records from Prospect ID //$prospectEntries = mysql_query('SELECT * FROM prospects ORDER BY prospect_id DESC ' . $queryLimit) or trigger_error(mysql_error()); $prospectEntries = mysql_query('SELECT * from prospects ORDER BY ".mysql_real_escape_string($orderby)." DESC '.$queryLimit) or trigger_error(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/197392-multiple-querysto-view-by-columns-in-db/#findComment-1036134 Share on other sites More sharing options...
shane85 Posted April 2, 2010 Author Share Posted April 2, 2010 perfect! thanks alot guys! Quote Link to comment https://forums.phpfreaks.com/topic/197392-multiple-querysto-view-by-columns-in-db/#findComment-1036195 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.