Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A question regarding select option pulldown using PHP 1

Status
Not open for further replies.

amirkhansemail

Programmer
Jan 22, 2007
11
CA
What should I write instead of the question marks in the first line to call news.php with the value n.news_id in the SQL Select statement

Code:
<form method="POST" name="news_selected_form" action="news.php?newsid=[b][u]?????????[/u][/b]">

	<select name="sel_news_id" onchange="news_selected_form.submit();">
	<?php

		$query="select n.news_id, n.title from news n";

		$result = @mysql_query($query);

		while ($row = mysql_fetch_array ($result, MYSQL_ASSOC))
			$news_pulldown .= "<option value=\"{$row['news_id']}\">{$row['title']}</option>\n";

		echo $news_pulldown;
	?>

	</select>

</form>

Your help is highly appreciated. Thanks in advance.
Amir
 
I have mentioned i want to pass n.news_id in the SQL Select Statement:

Code:
$query="select [b]n.news_id[/b], n.title from news n";
 
you don't need to. the value that the user selects in the list box will be available to the receiving script as
Code:
$_POST['sel_news_id']
 
Well your query has not run by the time you are trying to set the value of the action parameter of the form, so nothing from the DB is available at that point.

You have to put your query to before the form, and call mysql_fetch_array and have the information in the $row variable, then it would be something like:
Code:
<form method="POST" name="news_selected_form" action="news.php?newsid[red]<? echo $row['news_id'];?>[/red]">





----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top