| | |
Blank drop list
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2004
Posts: 13
Reputation:
Solved Threads: 0
Can someone show me where I go wrong. I am trying to populate a drop down list with field "type_desc" from the eventType table. Upon selection, the value that will be passed will be "type_code". All I am getting is a blank drop list. Can someone help.
Tablename: eventType
Fields:
type_code type=int auto-increase
type_desc type=text
<?
include 'db.php';
$sql_event_type = "select type_code,type_desc from eventType";
$sql_event_type_result = mysql_query($sql_event_type,$connection)
or die("Couldn't execute query.");
if ($sql_event_type_result) {
echo "<SELECT NAME='type_code'>";
while ($type_row = mysql_fetch_array($sql_event_type_result)){
echo "<OPTION VALUE=\"".$type_row["type_code"]."\">".
$type_row["type_desc"]." </OPTION> ";
}
echo "</SELECT>";
}
?>
Thanks
tip
Tablename: eventType
Fields:
type_code type=int auto-increase
type_desc type=text
<?
include 'db.php';
$sql_event_type = "select type_code,type_desc from eventType";
$sql_event_type_result = mysql_query($sql_event_type,$connection)
or die("Couldn't execute query.");
if ($sql_event_type_result) {
echo "<SELECT NAME='type_code'>";
while ($type_row = mysql_fetch_array($sql_event_type_result)){
echo "<OPTION VALUE=\"".$type_row["type_code"]."\">".
$type_row["type_desc"]." </OPTION> ";
}
echo "</SELECT>";
}
?>
Thanks
tip
•
•
Join Date: Feb 2003
Posts: 282
Reputation:
Solved Threads: 6
[php]while ($type_row = mysql_fetch_array($sql_event_type_result)){[/php]
Should this not be as below? (mysql_fetch_array to mysql_fetch_row)
[php]while ($type_row = mysql_fetch_row($sql_event_type_result)){[/php]
PS: In future, if you are putting PHP code here, please put surround it with the PHP tags. Just put [php] CODE HERE [/php]
Should this not be as below? (mysql_fetch_array to mysql_fetch_row)
[php]while ($type_row = mysql_fetch_row($sql_event_type_result)){[/php]
PS: In future, if you are putting PHP code here, please put surround it with the PHP tags. Just put [php] CODE HERE [/php]
•
•
Join Date: Feb 2003
Posts: 282
Reputation:
Solved Threads: 6
Actually it will. It's a valid result handle, irrelevant of its contents.
•
•
Join Date: Oct 2004
Posts: 3
Reputation:
Solved Threads: 0
[php]
<?
include 'db.php';
$sql_event_type = "
SELECT
type_code,
type_desc
FROM
eventType";
$sql_event_type_result = mysql_query($sql_event_type,$connection) or die("Couldn't execute query.");
// Debug
echo 'We have '.mysql_num_rows($sql_event_type_result).' in the database<br />';
if ($sql_event_type_result)
{
echo "<SELECT NAME='type_code'>";
while ($type_row = mysql_fetch_array($sql_event_type_result))
{
echo "<option value='".$type_row['type_code']."'>".$type_row['type_desc']."</option>";
}
echo "</SELECT>";
}
?>
[/php]
Cleaned up the formatting, removed the horrible escaping characters (you don't need these those if you differentiate between ' and " .. and added a debug call to make sure you are actually getting a result set back
<?
include 'db.php';
$sql_event_type = "
SELECT
type_code,
type_desc
FROM
eventType";
$sql_event_type_result = mysql_query($sql_event_type,$connection) or die("Couldn't execute query.");
// Debug
echo 'We have '.mysql_num_rows($sql_event_type_result).' in the database<br />';
if ($sql_event_type_result)
{
echo "<SELECT NAME='type_code'>";
while ($type_row = mysql_fetch_array($sql_event_type_result))
{
echo "<option value='".$type_row['type_code']."'>".$type_row['type_desc']."</option>";
}
echo "</SELECT>";
}
?>
[/php]
Cleaned up the formatting, removed the horrible escaping characters (you don't need these those if you differentiate between ' and " .. and added a debug call to make sure you are actually getting a result set back
![]() |
Similar Threads
- A Picture drop down list ? (JSP)
- Populate One Drop Down List From Another (ASP.NET)
- Populating a Drop-down List (PHP)
- view employee info for the employee selected from the drop down list (PHP)
- Data Binding to a Drop Down List? (ASP.NET)
- Passing a drop down list item's value (HTML and CSS)
Other Threads in the PHP Forum
- Previous Thread: Multiple PHP INCLUDES
- Next Thread: Please help us to beta-test PHP editor
| Thread Tools | Search this Thread |
301 access apache api array autocomplete beginner binary broken button cakephp checkbox class cms code compression cron curl data database date display dropdown dropdownlist duplicates dynamic echo email error execution file files folder form forms function functions google href htaccess html htmlspecialchars httppost image include insert integration ip javascript joomla jquery limit link links login mail md5 menu methods mlm multiple mysql oop paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote script search secure server session sessions sms source space sql subscription syntax system table tutorial update upload url validator variable video virus volume votedown web youtube





