Jump to content

Empty table row/record appears 1st in list of records


yandoo

Recommended Posts

Hi there,

 

I was hoping for a little help please  :D

 

I have a query that pulls records from a mysql database and displays them in a page.

 

My problem is that always the first record in the list is always empty, leaving an empty table row at the start of the records list.

 

If you have quick scan of code and see whats up that would be nice.

 

Thank You  :D

 

<table border="0" align="left" class="sortable">
  <tr>
    <td width="167" align="left"><strong>Name</strong></td>
    <td width="145" align="left"><strong>Earliest Sow</strong></td>
    <td width="107" align="left"><strong>Germination </strong></td>
    <td width="61" align="left"><strong>Containers</strong></td>
    <td width="92" align="left"> </td>
    <td width="92" align="left"> </td>
  </tr>
  <tr>
    <td align="left"> </td>
    <td align="left"> </td>
    <td align="left"> </td>
    <td align="left"> </td>
    <td align="left"> </td>
    <td align="left"> </td>
  </tr>

    <?php do { ?> <tr>
      <td align="left"><a href="vegetables3.php?recordID=<?php echo $result['VegetableID']; ?>">
        <input name="hiddenField" type="hidden" value="<?php echo $result['VegetableID']; ?>" />
                </a><a href="vegetables3.php?recordID=<?php echo $result['VegetableID']; ?>">
        <input name="hiddenField2" type="hidden" value="<?php echo $result['FamilyID']; ?>" />
                    </a><a href="vegetables3.php?recordID=<?php echo $result['VegetableID']; ?>">
        <input name="hiddenField3" type="hidden" value="<?php echo $result['TypeID']; ?>" />
        <input name="hiddenField4" type="hidden" value="<?php echo $result['EnviromentID']; ?>" />
        <input name="hiddenField5" type="hidden" value="<?php echo $result['Description']; ?>" />
                      </a> <a href="vegetables4.php?recordID=<?php echo $result['VegetableID']; ?>"><?php echo $result['Name']; ?></a></td>
      <td align="left"><?php echo $result['Sow']; ?></td>
      <td align="left"><?php echo $result['Proptime']; ?> Days </td>
      <td align="left"><input disabled="disabled"<?php if (!(strcmp($result['Pots'],1))) {echo "checked=\"checked\"";} ?> name="pots" type="checkbox" id="pots" value="checkbox" /></td>
      <td align="left"><?php echo "<img src=".$result['image']." height =\"60\" width=\"80\">"; ?></td>
      <td align="left"><?php

if ( $row_user['Access'] == "1" ) {?>
            <?php	
}?>        <a href="vegetables3.php?recordID=<?php echo $result['VegetableID']; ?>">Edit</a></td>
      </tr><?php } while ($result = mysql_fetch_assoc($data)); {?>
  </table>

   <?php
    }
	} 

	//This counts the number or results - and if there wasn't any it gives them a little message explaining that
	$anymatches=mysql_num_rows($data);
	if ($anymatches == 0)
	{
	echo "Sorry, but we can not finda an entry to match your query<br><br>";
	}

?>

do/while loops are almost never used because the first time through the loop, you would need to setup the data values. In your code, $result does not exists on the first pass through the loop because it is assigned inside of the while() statement at the end of the loop.

 

You should use a normal while() loop, not a do/while.

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.