473,387 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Selecting item from populated dropdown list and displaying results from database

4
Hey there

I am using phpMyAdmin and MySQL to develop a dbase application.

I have a dropdown menu on one of the pages which gets populated automatically with data from a table in the database. The code for this is as follows:

Expand|Select|Wrap|Line Numbers
  1. $sql3="SELECT ID, UploadDate FROM Telkom"; 
  2. $result2=mysql_query($sql3); 
  3. $options=""; 
  4.  
  5. while ($row=mysql_fetch_array($result2)) { 
  6.  
  7.     $id=$row["ID"]; 
  8.     $date=$row["UploadDate"]; 
  9.     $options.="<OPTION VALUE=\"$id\">".$date;
  10.  
  11. The code for the actual dropdown menu is as follows:
  12.  
  13.  <form name="selectdata" action="select_telkom_data.php" method="post">
  14.         <SELECT NAME="thedate">
  15.           <OPTION>Choose 
  16.           <?=$options?>
  17.         </SELECT>
  18.         <input type="submit" name="Submit" value="Go">
  19.       </form>
  20.  
  21. As you can see there is an additional php script (select_telkom_data.php). This script is supposed to check the $date variable against the UploadDate table and then return the correct record based on the date the user has selected in the dropdown menu.
  22.  
  23. The code for select_telkom_data.php looks like this:
  24.  
  25. <?php
  26.  
  27.     include "admin/dataw.php";
  28.     include("global.inc.php");
  29.     $sysadminemail = "webmaster@dtmsi.org";
  30.  
  31.        process_login();
  32.        die();
  33.  
  34.  
  35.     function process_login() {
  36.         global $dbhost;
  37.         global $dbuser;
  38.         global $dbpass;
  39.         global $db;
  40.  
  41.         // define homepage and text variables
  42.         global $homepage;
  43.         global $homedir;
  44.         global $sysadminemail;
  45.         global $userstable;
  46.  
  47.  
  48.         $date=$_POST['thedate'];
  49.         $link = mysql_connect("$dbhost", "$dbuser", "$dbpass")
  50.         or die('Could not connect: ' . mysql_error());
  51.         echo 'Connected successfully';
  52.         mysql_select_db("$db") or die('Could not select database');
  53.  
  54.         $query = "SELECT * FROM Telkom WHERE UploadDate='$date' ";
  55.         $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  56.  
  57.  
  58.         $num_rows = mysql_num_rows($result);
  59.         $row = mysql_fetch_array($result);
  60.  
  61.  
  62.         // test -- does the date exist
  63.         if ($num_rows < 1) {
  64.             print "<HTML>";
  65.             print "<HEAD>";
  66.             print "<TITLE>";
  67.             print "Error";
  68.             print "</TITLE>";
  69.             print "<BODY>";
  70.             print "<CENTER>";
  71.             print "<B><CENTER>Sorry - no records exist. ";
  72.  
  73.  
  74.         }
  75.         else {
  76.  
  77.  
  78.            include("show_telkom_data.php");
  79.  
  80.                 mysql_close($link);
  81.             }
  82.  
  83.  
  84.     }
  85.  
  86. ?>
[Please use CODE tags when posting source code. Thanks! --pbmods]

The script connects to the database, but it doesn't return any records from the Telkom table. In other words, all I get is the message 'Sorry - no records exist'.

What am I doing wrong?

Thanks guys!
Panna
Jul 3 '07 #1
4 3408
kovik
1,044 Expert 1GB
The value that you are getting from your selection is not the UploadDate, it's the id. The UploadDate is just the label of the option, not the value of it.

if you print_r($_POST), you'll see the values that are being passed from the form.
Jul 3 '07 #2
Panna
4
The value that you are getting from your selection is not the UploadDate, it's the id. The UploadDate is just the label of the option, not the value of it.

if you print_r($_POST), you'll see the values that are being passed from the form.
ok, thanks very much! Just one more question though: I'm not entirely sure what to change to make it work. I would REALLY appreciate if you could help me out one more time.
shot!
Jul 3 '07 #3
kovik
1,044 Expert 1GB
Think about it.


What condition are you using to get the data from your database?
What values are you provided to get that data?

Like I said, use print_r($_POST) and figure it out. ^_^
Jul 3 '07 #4
Panna
4
hey, thanks for all your help! I managed to figure it out up to a point where the correct records get selected and displayed.
panna
Jul 3 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Lukelrc | last post by:
Hi, I have a dynamically created listbox. I'm trying to get one of the options selected according to a passed value. This is what i have: <select name="txtTheme" id="txtTheme"> ...
5
by: Kris Rockwell | last post by:
Hello (again), I have gotten the dropdown list functionality to work through a few tricks (probably not the most efficient, but it works) but I am not sure how to set the default selected value....
4
by: Merdaad | last post by:
My drop down list is populated from a static array in my codebehind (c#) code. I set the selected index based on some known values(from DB), when the screen shows up, dropdown list shows that the...
6
by: Mike Wilson | last post by:
Dear Group, I have a heirarchical set of database tables, say - "order" and "order_type" and want to display a series of orders in a grid control, and in place of the order_type foreign key...
0
by: koti | last post by:
hi i have written some code for selecting an item in combobox dropdown list which is in datagrid columm. by scrolling the mouse we select any item from the list. but by pressing the down key...
5
by: glenn | last post by:
Hi folks, If I want to select the first item in a DropDownList, I need to first select any item other than the first item and then next I select the first item which will then fire an event...
4
by: =?Utf-8?B?UmljaA==?= | last post by:
Greetings, I have to load 30,000 unique names into a combox. Filling a dataTable takes only a few milliseconds. But populating the combobox and displaying the list takes several seconds - way...
4
by: Ronny Mandal | last post by:
Hi! I have an .aspx with some controls that are created dynamically. The items are populated into the box by setting the DataSource-property to a list. In addition I specify the text and value...
2
by: SunnySnow29 | last post by:
Hi, I have a 2 drop down lists in C# populated with data from a SQL 2005 db. When a new item of data is inserted the second list must update to reflect the change (the first drop down list will...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.