Jump to content

Syntax Help


Zergman

Recommended Posts

Im trying to show a dropdown if records exist, but can't figure out the syntax.

 

Here's the dropdown I want to show.

<select name="tracking" class="inputbox" id="tracking">
          <?php
do {  
?>
          <option value="<?php echo $row_rsmenufield['value']?>"><?php echo $row_rsmenufield['value']?></option>
          <?php
} while ($row_rsmenufield = mysql_fetch_assoc($rsmenufield));
  $rows = mysql_num_rows($rsmenufield);
  if($rows > 0) {
      mysql_data_seek($rsmenufield, 0);
  $row_rsmenufield = mysql_fetch_assoc($rsmenufield);
  }
?>
        </select>

 

If I do this, get syntax error

<?php
if ($totalRows_rsmenufield > 0) {
<select name="tracking" class="inputbox" id="tracking">
          <?php
do {  
?>
          <option value="<?php echo $row_rsmenufield['value']?>"><?php echo $row_rsmenufield['value']?></option>
          <?php
} while ($row_rsmenufield = mysql_fetch_assoc($rsmenufield));
  $rows = mysql_num_rows($rsmenufield);
  if($rows > 0) {
      mysql_data_seek($rsmenufield, 0);
  $row_rsmenufield = mysql_fetch_assoc($rsmenufield);
  }
?>
</select>
}

if ($totalRows_rsmenufield < 0) {
Nothing currently being tracked
}
?>

 

Help! lol  ???

Link to comment
Share on other sites

You seem to have a few things wrong

 

<?php
if ($totalRows_rsmenufield > 0) {
<select name="tracking" class="inputbox" id="tracking">
          <?php  //you start php but you didn't close it
do {  
?>
          <option value="<?php echo $row_rsmenufield['value']?>"><?php echo $row_rsmenufield['value']?></option>
          <?php
} while ($row_rsmenufield = mysql_fetch_assoc($rsmenufield)); //missing { } for while loop
  $rows = mysql_num_rows($rsmenufield); 
  if($rows > 0) {
      mysql_data_seek($rsmenufield, 0);
  $row_rsmenufield = mysql_fetch_assoc($rsmenufield);
  }
?>
</select>
}

if ($totalRows_rsmenufield < 0) {
Nothing currently being tracked
}
?>

Link to comment
Share on other sites

Thanks for the pointers revraz.  I've double checked my php tags and stuff but from what I can see, they seem to be good ... apparently not, but can't seem to locate my error right now.

 

Been at this for about 19hrs straight so my eyes and brain are done lol.  I'll go over it again once I got my marbles straight.

 

Thanks again for the help.

Link to comment
Share on other sites

Here is the right syntax for your code, but you still have logic/coding issues.  You may be missing a closing } because I can't follow your code or what you are trying to do.

 

<?php
if ($totalRows_rsmenufield > 0) {
echo '<select name="tracking" class="inputbox" id="tracking">';

do {  
?>
          <option value="<?php echo $row_rsmenufield['value']?>"><?php echo $row_rsmenufield['value']?></option>
          <?php
} 
while ($row_rsmenufield = mysql_fetch_assoc($rsmenufield)); //don't know what you are trying to do here
  $rows = mysql_num_rows($rsmenufield); 
  if($rows > 0) {
      mysql_data_seek($rsmenufield, 0);
  $row_rsmenufield = mysql_fetch_assoc($rsmenufield);
  }

echo "</select>";
}

if ($totalRows_rsmenufield < 0) {
echo "Nothing currently being tracked";
}
?>

Link to comment
Share on other sites

Here is a simple way to add options to a pulldown, this is from my site that I use to grab boat names to populate a list.

 

<select name="bid">
<?php
$getboats = "SELECT * FROM boats WHERE bstatus = 1";
$getresult = mysql_query($getboats) or die (mysql_error());
           if (mysql_num_rows($getresult) > 0) {
	while ($boatlist= mysql_fetch_assoc($getresult)){
	echo "<option value={$boatlist['bid']}>{$boatlist['bname']}</option>";
	}	
}
else {
	echo "<a href='boatadmin.php'>No Boats found, check status</a>";
	exit;
}	

?>
</select>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.