Jump to content

[SOLVED] record count on jump to menu


yukafluck

Recommended Posts

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

 

 ( )

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.