954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Blank drop list

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 "";
while ($type_row = mysql_fetch_array($sql_event_type_result)){
echo "".
$type_row["type_desc"]." ";
}
echo "";
}
?>

Thanks
tip

tip
Newbie Poster
13 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

[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]

Roberdin
Supreme Evil Overlord
Team Colleague
282 posts since Feb 2003
Reputation Points: 63
Solved Threads: 6
 

OK Roberdin. No it still does not make any difference.

tip

tip
Newbie Poster
13 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

Are you syre that the query is returning a result?

Roberdin
Supreme Evil Overlord
Team Colleague
282 posts since Feb 2003
Reputation Points: 63
Solved Threads: 6
 

Yes it returns a result. Correct me if I am wrong, but if it doesn't it won't pass the if statement test and won't display a blank list. Been working on this all morning without much success.

ta

tip

tip
Newbie Poster
13 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

Actually it will. It's a valid result handle, irrelevant of its contents.

Roberdin
Supreme Evil Overlord
Team Colleague
282 posts since Feb 2003
Reputation Points: 63
Solved Threads: 6
 

[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
';

if ($sql_event_type_result)
{
echo "";
while ($type_row = mysql_fetch_array($sql_event_type_result))
{
echo "".$type_row['type_desc']."";
}
echo "";
}
?>
[/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 :)

Shorty
Newbie Poster
3 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
 

Thank you very much Shorty. I have another question - this code works if a new event is added, where its type is selected from the list. How can I modify the code to enable me to edit an existing event with its type.

Thanks again Shorty

tip

tip
Newbie Poster
13 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You