Page 1 of 1

Creating Jump Menu With PHP

Posted: Wed Jan 17, 2007 1:59 am
by jnfields
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am relatively new to PHP and I am having trouble implementing PHP code to create a "jump menu"...

Code: Select all

<select name="menu1" onchange="MM_jumpMenu('parent',this,0)">
<? $db_host = "mysql"; $db_username = "user"; $db_password = "pass";
     $db_name = "DATABASE"; $tbl_name = "TABLE";
     mysql_connect ($db_host, $db_username, $db_password);
     @mysql_select_db($db_name) or die ("Unable to select the database: $db_name");
  
     $notstatus = 10;
     $query = "SELECT * FROM $tbl_name WHERE Status!='$notstatus'";
     $result = mysql_query($query);
		
     $count = mysql_num_rows($result);
     $i = 0;
			
     while ($i < $count)
     {
        $qid = mysql_result($result, $i, "QID");
?>	
       <option value="FOLDER/FILE.php?qid=<? echo $qid; ?>"><? echo $qid; ?></option><br />
<? 
     $i++;
     }
     $mysql_close();
?>
</select>
The code will produce the proper jumpmenu that I want it to...however when you look at the source code when the page renders the "</select>" and all the code after it doesn't appear.

Not much good unless the jump menu is the last thing on the page...any clues as to what I'm doing wrong?

Thanks!
jnf


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Jan 17, 2007 2:03 am
by jnfields
Ok, the "<br />" isn't at the end of the option line if that matters...

Posted: Wed Jan 17, 2007 4:42 am
by Grim...
Please put

Code: Select all

tags around your code.

Code: Select all

</select>
seems to be at the end of your code anyway, but you might want to get rid of that line of '*******'.

Posted: Wed Jan 17, 2007 4:55 am
by Grim...
If I may, I'd like to suggest a 'cleaner' (and easier, IMO) way of doing a MySQL result loop:

Code: Select all

<?php
$result=mysql_query("SELECT id, name, address FROM thistable");
$rows = mysql_fetch_array($result);
foreach ($rows as $row)
{
	echo $row['id']."<br />";
	echo $row['name']."<br />";
	echo $row['address']."<br />";
}
?>
I know everyone has their own style, but the code above seems simpler (to me) than the code you are using.