Blank drop list

Reply

Join Date: Sep 2004
Posts: 13
Reputation: tip is an unknown quantity at this point 
Solved Threads: 0
tip tip is offline Offline
Newbie Poster

Blank drop list

 
0
  #1
Oct 20th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 282
Reputation: Roberdin will become famous soon enough Roberdin will become famous soon enough 
Solved Threads: 6
Team Colleague
Roberdin Roberdin is offline Offline
Supreme Evil Overlord

Re: Blank drop list

 
0
  #2
Oct 20th, 2004
[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]
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 13
Reputation: tip is an unknown quantity at this point 
Solved Threads: 0
tip tip is offline Offline
Newbie Poster

Re: Blank drop list

 
0
  #3
Oct 20th, 2004
OK Roberdin. No it still does not make any difference.

tip
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 282
Reputation: Roberdin will become famous soon enough Roberdin will become famous soon enough 
Solved Threads: 6
Team Colleague
Roberdin Roberdin is offline Offline
Supreme Evil Overlord

Re: Blank drop list

 
0
  #4
Oct 20th, 2004
Are you syre that the query is returning a result?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 13
Reputation: tip is an unknown quantity at this point 
Solved Threads: 0
tip tip is offline Offline
Newbie Poster

Re: Blank drop list

 
0
  #5
Oct 20th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 282
Reputation: Roberdin will become famous soon enough Roberdin will become famous soon enough 
Solved Threads: 6
Team Colleague
Roberdin Roberdin is offline Offline
Supreme Evil Overlord

Re: Blank drop list

 
0
  #6
Oct 21st, 2004
Actually it will. It's a valid result handle, irrelevant of its contents.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3
Reputation: Shorty is an unknown quantity at this point 
Solved Threads: 0
Shorty Shorty is offline Offline
Newbie Poster

Re: Blank drop list

 
0
  #7
Oct 21st, 2004
[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
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 13
Reputation: tip is an unknown quantity at this point 
Solved Threads: 0
tip tip is offline Offline
Newbie Poster

Re: Blank drop list

 
0
  #8
Oct 21st, 2004
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC