Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    Question messy code please help

    I think I'm nearly there, I just want to display a drop down list

    Code:
    <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:
    Code:
    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?

  • #2
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,378
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    echo "<option value=\"pub_info.php?rsTown={$row['rsTown']}\">{$row['rsTown']} &nbsp;({$total_pages})</option>";

  • #3
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    356
    Thanks
    19
    Thanked 2 Times in 2 Posts
    You forgot the "$" before row. ($row = variable). That's all you need to change

    PHP Code:
    echo '<option value=\"pub_info.php?rsTown='.$row['rsTown'].'\">';
                    echo 
    ''.$row['rsTown'].'&nbsp;('.$total_pages.')</option>'
    Last edited by sitNsmile; 12-06-2010 at 12:33 PM.

  • #4
    New Coder
    Join Date
    Nov 2010
    Posts
    15
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by jarv View Post
    I think I'm nearly there, I just want to display a drop down list

    Code:
    <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:
    Code:
    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.
    Code:
    echo '<option value="pub_info.php?rsTown='.row["rsTown"].'">';
    				echo $row['rsTown'] . '&nbsp;(' .$total_pages. ')</option>';

  • #5
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,378
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •