...

View Full Version : messy code please help



jarv
12-06-2010, 01:10 PM
I think I'm nearly there, I just want to display a drop down list



<ul>
<li><form name="form3" method="post" action="">
<select name="menu2" onChange="MM_jumpMenu('parent',this,0)" class="textbox">
<option value="">Please choose a town!</option>
<?php while($row = mysql_fetch_array($result))
{
echo '<option value=\"pub_info.php?rsTown='.row['rsTown'].'\">';
echo ''.row['rsTown'].'&nbsp;('.$total_pages.')</option>';
}
echo '</select>';
echo '</form>';
?>
</li>
</ul>


my error lies on line 465 which is this bit:
echo '<option value=\"pub_info.php?rsTown='.row['rsTown'].'\">';
echo ''.row['rsTown'].'&nbsp;('.$total_pages.')</option>';


but I think my code is just a mess?! what do you think?

mlseim
12-06-2010, 01:23 PM
echo "<option value=\"pub_info.php?rsTown={$row['rsTown']}\">{$row['rsTown']} &nbsp;({$total_pages})</option>";

sitNsmile
12-06-2010, 01:31 PM
You forgot the "$" before row. ($row = variable). That's all you need to change :)


echo '<option value=\"pub_info.php?rsTown='.$row['rsTown'].'\">';
echo ''.$row['rsTown'].'&nbsp;('.$total_pages.')</option>';

syncupsolutions
12-06-2010, 01:48 PM
I think I'm nearly there, I just want to display a drop down list



<ul>
<li><form name="form3" method="post" action="">
<select name="menu2" onChange="MM_jumpMenu('parent',this,0)" class="textbox">
<option value="">Please choose a town!</option>
<?php while($row = mysql_fetch_array($result))
{
echo '<option value=\"pub_info.php?rsTown='.row['rsTown'].'\">';
echo ''.row['rsTown'].'&nbsp;('.$total_pages.')</option>';
}
echo '</select>';
echo '</form>';
?>
</li>
</ul>


my error lies on line 465 which is this bit:
echo '<option value=\"pub_info.php?rsTown='.row['rsTown'].'\">';
echo ''.row['rsTown'].'&nbsp;('.$total_pages.')</option>';


but I think my code is just a mess?! what do you think?


Theres no need to escape " inside of a query wrapped in single quotes.


echo '<option value="pub_info.php?rsTown='.row["rsTown"].'">';
echo $row['rsTown'] . '&nbsp;(' .$total_pages. ')</option>';

mlseim
12-06-2010, 08:46 PM
I did the "escaped quotes" so that when he views the HTML, it will look
the same as the rest of his form tags. Merely for visual appeal.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum