yukafluck Posted May 28, 2009 Share Posted May 28, 2009 I have a piece of code that generates a jump to menu, using a group by query. What I would like to do is be able to have it shows the number of records for each options. right now the option for 2009 would show "2009", I would like it to show: "2009 (3)". Here is the code that I have: <form name="Year" id="Year"> <select name="YearMenu" onchange="MM_jumpMenu('parent',this,0)"> <option selected="selected">Choose</option> <?php include_once "_functions/db_info.php"; //connect to database $dbserver = mysql_connect($hostname, $dbuser, $dbpswd); $connection = $dbserver or die ('I cannot connect to the server'); mysql_select_db ($dbname) or die ('I cannot connect to the database'); $sqlGetVehicleYear="SELECT * FROM vehicles GROUP BY vehicle_year DESC; "; $sqlGetVehicleYearRes = mysql_query($sqlGetVehicleYear,$connection) or die ("could not connect to sqlGetVehicleYear "); While ($row = mysql_fetch_array($sqlGetVehicleYearRes)) { $vehicle_year=$row["vehicle_year"]; ?> <option value="vehicles_list.php?makenarrow=%&yearnarrow=<?php echo $vehicle_year ?>"><?php echo $vehicle_year ?></option> <?php }?> </select> </form> [code=php:0] Any help would be greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/160062-solved-record-count-on-jump-to-menu/ Share on other sites More sharing options...
Maq Posted May 28, 2009 Share Posted May 28, 2009 You can use COUNT() in your query to achieve this. Quote Link to comment https://forums.phpfreaks.com/topic/160062-solved-record-count-on-jump-to-menu/#findComment-844414 Share on other sites More sharing options...
yukafluck Posted May 28, 2009 Author Share Posted May 28, 2009 not to sound like a complete numbnut, but how? Quote Link to comment https://forums.phpfreaks.com/topic/160062-solved-record-count-on-jump-to-menu/#findComment-844427 Share on other sites More sharing options...
Maq Posted May 28, 2009 Share Posted May 28, 2009 Click on the link I provided, there are plenty of examples there are similar to yours. If you can't figure it out, post back with what you tried and why it doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/160062-solved-record-count-on-jump-to-menu/#findComment-844432 Share on other sites More sharing options...
yukafluck Posted May 28, 2009 Author Share Posted May 28, 2009 ok, all you need to do is point me in the direction to have it show with the echo statement Quote Link to comment https://forums.phpfreaks.com/topic/160062-solved-record-count-on-jump-to-menu/#findComment-844450 Share on other sites More sharing options...
Maq Posted May 28, 2009 Share Posted May 28, 2009 Change your query to: SELECT COUNT(*) as num, * FROM vehicles GROUP BY vehicle_year DESC And to display the number for each one change your menu output to: ( ) Quote Link to comment https://forums.phpfreaks.com/topic/160062-solved-record-count-on-jump-to-menu/#findComment-844455 Share on other sites More sharing options...
yukafluck Posted May 28, 2009 Author Share Posted May 28, 2009 tried that, and it just stops no errors or anything Quote Link to comment https://forums.phpfreaks.com/topic/160062-solved-record-count-on-jump-to-menu/#findComment-844459 Share on other sites More sharing options...
yukafluck Posted May 28, 2009 Author Share Posted May 28, 2009 and just has the first option listed Quote Link to comment https://forums.phpfreaks.com/topic/160062-solved-record-count-on-jump-to-menu/#findComment-844461 Share on other sites More sharing options...
Maq Posted May 28, 2009 Share Posted May 28, 2009 Then do this: SELECT COUNT(*) num, vehicle_year FROM vehicles GROUP BY vehicle_year DESC Quote Link to comment https://forums.phpfreaks.com/topic/160062-solved-record-count-on-jump-to-menu/#findComment-844465 Share on other sites More sharing options...
yukafluck Posted May 28, 2009 Author Share Posted May 28, 2009 That's the ticket, you are awesome I've been trying to figure it out for two days Quote Link to comment https://forums.phpfreaks.com/topic/160062-solved-record-count-on-jump-to-menu/#findComment-844467 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.