Creating Jump Menu With PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jnfields
Forum Newbie
Posts: 2
Joined: Wed Jan 17, 2007 1:49 am

Creating Jump Menu With PHP

Post 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]
jnfields
Forum Newbie
Posts: 2
Joined: Wed Jan 17, 2007 1:49 am

Post by jnfields »

Ok, the "<br />" isn't at the end of the option line if that matters...
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post 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 '*******'.
Last edited by Grim... on Wed Jan 17, 2007 4:57 am, edited 1 time in total.
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post 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.
Post Reply