wkilc Posted June 23, 2008 Share Posted June 23, 2008 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 More sharing options...
plutomed Posted June 23, 2008 Share Posted June 23, 2008 if($_GET['instrument'] == " . $row['instrument'] . "){ echo "selected=\"selected\""; } In this, why have you quoted " . $row['instrument'] . " Link to comment https://forums.phpfreaks.com/topic/111536-solved-syntax-error/#findComment-572456 Share on other sites More sharing options...
wkilc Posted June 23, 2008 Author Share Posted June 23, 2008 In this, why have you quoted " . $row['instrument'] . " In short... because I'm and idiot. Here was the solution: if($_GET['instrument'] == $row['instrument'] ){ echo "selected=\"selected\""; } Thanks very much! ~Wayne Link to comment https://forums.phpfreaks.com/topic/111536-solved-syntax-error/#findComment-572464 Share on other sites More sharing options...
plutomed Posted June 23, 2008 Share Posted June 23, 2008 No probs. Link to comment https://forums.phpfreaks.com/topic/111536-solved-syntax-error/#findComment-572474 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.