Adding row counts to generated drop down menu list?
Posted: Mon Nov 08, 2004 9:04 am
Hi, I am a relative newbie. I have created a webpage with php which calls a postgresql database and then populates a drop down menu with the results of the search.
Based on the selection from the menu the "user" is presented with a new page with another
drop down menu whose entries are based on the first selection and so on. This all works nicely.
What I would like to do now is add some bells and whistles. One thing I would like to do
is to indicate next to each entry in these drop down menus how many items in the database satisfy that particular search criteria. I have played around with the select count function but I haven't gotten it to do what I want. I have included a snippet of code below.
What I would like displayed in the drop down menu is
Year1 (#)
Year2 (#)
Year3 (#)
where # refers to the number of entries in the database which satisfy search criteria Year1.
Any help to incorporate this feature into my existing code would be greatly appreciated.
Here is the code so far...
Any help would be greatly appreciated.
R Haynes
Next to each entry
Weirdan | Help us, help you. Please use
Based on the selection from the menu the "user" is presented with a new page with another
drop down menu whose entries are based on the first selection and so on. This all works nicely.
What I would like to do now is add some bells and whistles. One thing I would like to do
is to indicate next to each entry in these drop down menus how many items in the database satisfy that particular search criteria. I have played around with the select count function but I haven't gotten it to do what I want. I have included a snippet of code below.
What I would like displayed in the drop down menu is
Year1 (#)
Year2 (#)
Year3 (#)
where # refers to the number of entries in the database which satisfy search criteria Year1.
Any help to incorporate this feature into my existing code would be greatly appreciated.
Here is the code so far...
Code: Select all
<?php
$connection = pg_connect(blah, blah,blah);
if (!$connection) {
print("Connection Failed.");
exit;
}
$query = "select distinct year from tradelist where quantity > 0 order by year";
$myresult = pg_exec($connection,$query);
$num_rows = pg_numrows($myresult);
$query2 = "select * from tradelist";
$myresult2 = pg_exec($connection,$query2);
$num_rows2 = pg_numrows($myresult2);
print("<p>There are currently <font color=blue> $num_rows2 </font> entries in the tradelist database<br>");
if ($num_rows == 0) {
print("No records exist");
}
else {
print("<FORM METHOD="POST" ACTION="blah...">");
print("Choose a year from which to search ...<br><br>");
print("<font color=blue>Available Years</font><br><br>");
print("<SELECT NAME="year_to_search">");
while ($row = pg_fetch_array($myresult))
{
$id = $row["year"];
print("<OPTION VALUE = "$id"> $id");
}
}
print("</select>");
print("<INPUT TYPE="SUBMIT" VALUE="VIEW SETS BY YEAR">");
print("<INPUT TYPE="RESET" VALUE="RESET">");
print("</FORM>");
?>R Haynes
Next to each entry
Weirdan | Help us, help you. Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]