944,015 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 4716
  • PHP RSS
Oct 20th, 2004
0

Blank drop list

Expand Post »
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
Similar Threads
tip
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tip is offline Offline
13 posts
since Sep 2004
Oct 20th, 2004
0

Re: Blank drop list

[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]
Team Colleague
Reputation Points: 63
Solved Threads: 6
Supreme Evil Overlord
Roberdin is offline Offline
282 posts
since Feb 2003
Oct 20th, 2004
0

Re: Blank drop list

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

tip
tip
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tip is offline Offline
13 posts
since Sep 2004
Oct 20th, 2004
0

Re: Blank drop list

Are you syre that the query is returning a result?
Team Colleague
Reputation Points: 63
Solved Threads: 6
Supreme Evil Overlord
Roberdin is offline Offline
282 posts
since Feb 2003
Oct 20th, 2004
0

Re: Blank drop list

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tip is offline Offline
13 posts
since Sep 2004
Oct 21st, 2004
0

Re: Blank drop list

Actually it will. It's a valid result handle, irrelevant of its contents.
Team Colleague
Reputation Points: 63
Solved Threads: 6
Supreme Evil Overlord
Roberdin is offline Offline
282 posts
since Feb 2003
Oct 21st, 2004
0

Re: Blank drop list

[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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Shorty is offline Offline
3 posts
since Oct 2004
Oct 21st, 2004
0

Re: Blank drop list

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tip is offline Offline
13 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Multiple PHP INCLUDES
Next Thread in PHP Forum Timeline: Please help us to beta-test PHP editor





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC