473,795 Members | 2,498 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Selecting item from populated dropdown list and displaying results from database

4 New Member
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 3432
kovik
1,044 Recognized Expert Top Contributor
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 New Member
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 Recognized Expert Top Contributor
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 New Member
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
2071
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"> <option>Select Theme</option> <% Dim PassedTheme
5
10841
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. I have tried setting various values to represent the default value with little success. Essentially I am looking to have the first item in the list be the default selected item. I noticed in the properties for a dtat grid you could set a default...
4
2717
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 the first items is selected and not the one assigned. Please note that if I hardcode the dropdown items inside the .aspx file, everything works fine. Please point me to examples(infopath examples somehow don't show up for me!).
6
3153
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 identifier, I would like a dropdown combo box (lookup from the "order_type" table) to change the type of the order. I also need an update command button, a delete row button and also an insert new row button. I'm sure this is a very common design...
0
2085
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 arrow it is not working can u tell me what are the properties i have to add to slect an item in processcmdkey method.
5
9905
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 saying that I clicked the first item. Why can't I just select the first item to get an event to fire without having to first select any other item. Thanks for any tips.
4
5112
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 too long. A user selects a name from the combobox and runs a query. Originally, this combox was on a form in an MS Access ADP which was linked directly to our sql server. The combobox populated withins millisecnods. How can I achieve this...
4
2515
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 with DataTextField and DataValueField; this works as expected. However, my problems arises when I want to read the selected value (i.e. after a postback caused by a change in the DropDown), the selected item is always the first item in the...
2
1706
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 always be unchanged by inserts) and the new value must become the selected value in drop down list 2. I use databind() after the form has autoposted back after the insert but the 1st and 2nd drop down lists default back to the first item in the...
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.