Jump to content

[SOLVED] syntax error


wkilc

Recommended Posts

I am trying to use my very limited knowledge to merge two working scripts.

 

The short version, this is giving me a syntax error:

if($_GET['instrument'] == " . $row['instrument'] . "){ echo "selected=\"selected\""; }  

Error - unexpected T_ENCAPSED_AND_WHITESPACE

 

More details...

 

This generates a nice pulldown menu from a database, no duplicate, redundant rows:

 

<form name="form" action="index.php" method="get">
$result = @mysql_query("select distinct cars * from mytable");
if (mysql_num_rows($result) > 0) {
print "<select name=\"cars\">"; 
while ($row = mysql_fetch_array($result)) {
print "<option value=\"" . $row['cars'] . "\">" . $row['cars'] . "</option>\n";
}
print "</select>";
}
mysql_free_result($result);  
?>
<input type="submit" value="Go">
</form>

 

This static menu creates and echo "selected" for the selected value of the menu, so it remains as the selected choice value in the menu:

<form name="form" action="index.php" method="get">
<select name="car">
<option <?php if(empty($_GET['car'])){ echo "selected=\"selected\""; } ?> value="">DISPLAY ALL</option>
<option <?php if($_GET['car'] == "honda"){ echo "selected=\"selected\""; } ?> value="honda">honda</option>
<option <?php if($_GET['car'] == "toyota"){ echo "selected=\"selected\""; } ?> value="toyota">toyota</option>
<option <?php if($_GET['car'] == "ford"){ echo "selected=\"selected\""; } ?> value="ford">ford</option>
</select>
 <input type="submit" value="Go">
</form>

 

I am trying to use the echo select on the first "dynamic" menu:

 

<form name="form" action="index.php" method="get">
<?
$result = @mysql_query("select distinct instrument from bocj ORDER BY instrument ASC");
if (mysql_num_rows($result) > 0) {
print "<select name=\"instrument\">"; 
while ($row = mysql_fetch_array($result)) {
print "<option ";
if($_GET['instrument'] == " . $row['instrument'] . "){ echo "selected=\"selected\""; }  
print " value=\"" . $row['instrument'] . "\">" . $row['instrument'] . "</option>\n";
}
print "</select>";
}
mysql_free_result($result);  
?>
 <input type="submit" value="Go">
</form>

 

Thanks once again.

 

~Wayne

Link to comment
https://forums.phpfreaks.com/topic/111536-solved-syntax-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.