Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old September 26th, 2003, 10:20 PM
skylander skylander is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 5 skylander User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Retrieving data for Drop down list.

Hi everyone,

I am writing a PHP/HTML form that retrieve some data from MySQL database. However, I have problem on the drop down list. I want to retrieve two set of table: The first set of data will be used as the data of the dropdown list. The second data (one string) is the inputted data from users.
I would like to compare the user inputted data and the dropdown list data. If the entry is the same, then "selected" that entry for the drop downlist. So that users know what the current selection is.

I can retrieved the list for dropdown. However, I have problem to compare and "selected" the current entry.

Can anyone help me on this issue? Thank you very much in advance.

Regards,
Vincent

--- Here is my sloppy code:

<Html>
<head>
<title>Detail testing </title></head>

<body>
<select name="site">
<?php

$db = mysql_connect("localhost", "root", "p3pp3r");
mysql_select_db("equestdb", $db);
$db2 = mysql_connect("localhost", "root", "p3pp3r");
mysql_select_db("equestdb", $db2);

//get the id
$id= $_GET["id"];

//for listing the user inputted data.
$rs_detail = mysql_query("Select * from eqbase where eq_id= '$id'", $db);

// using for dropdown list data
$rs_sitelist = mysql_query("Select * from site_id order by site_id", $db1);

if($mysitelist=mysql_fetch_array($rs_sitelist)){ // list dropdown
do{
$site_v = $mysitelist["site_val"];
if ($myblist=mysql_fetch_array($rs_detail))
{
$site_n = $myblist["site"];

if ($site_n == $site_v ){ // try to compare userinputted data.
$theone="selected";
printf("<option value='%s' %s >%s</option>", $mysitelist["site_val"], $theone, $mysitelist["site_nam"]);
// if the same, print selected on that option list
}
}
printf("%s",$mysitelist["site_val"]);
printf("<option value='%s' %s >%s</option>", $mysitelist["site_val"], $theone, $mysitelist["site_nam"]);
}
while ($mysitelist = mysql_fetch_array($rs_sitelist));
}
else {
echo "No Records!!";
}
?>
</select>

</body>
</Html>

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Retrieving data for Drop down list.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway