Jump to content

loop through returned records from query


kenny22

Recommended Posts

Have a web page that displays a number of update forms depending on the amout of records that get returned from a mysql query, if query returns 4 records then the page will display 4 identical forms, the trouble i'm having is getting the each  of the 4 forms to display a different record as at the moment they all show just first record of query.

 

I have played around with loops but not getting anywhere which may be due to my limited knowledge code for page is below

 

 <?php $numberofrow =mysql_num_rows($Recordset1);

for($counter = 1;$counter<=$numberofrow;$counter++){ 
?>
  <label for="hometeam2"></label>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  <label for="hometeam"></label>


  
  <input name="fixid" type="text" id="fixid" value="<?php echo $row_Recordset1['FixtureID']; ?>" />
  <input name="hometeam" type="text" id="hometeam2" value="<?php echo $row_Recordset1['hometeamname']; ?>" />
  <label for="homescore"></label>
  <input name="homescore" type="text" id="homescore" value="<?php echo $row_Recordset1['homescore']; ?>" />
  <label for="awayscore"></label>
  <label for="fixid"></label>
  <input name="awayscore" type="text" id="awayscore" value="<?php echo $row_Recordset1['awayscore']; ?>" />
<label for="awayteam"></label>
<input name="awayteam" type="text" id="awayteam" value="<?php echo $row_Recordset1['awayteamname']; ?>" />
<input type="submit" name="update" id="update" value="Submit" />
<input type="hidden" name="MM_update" value="form1" />

:D  thank you it works 95%, only problem is it misses out first record,  if query returns 4 it will still show 4 forms but only 3 records leaving 1 form blank

 

kenny

 

Edit: :D :D :D

code now working 100% had to remove

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

from after select query as that was 1st record and was getting lost

 

Many thanks again

It sounds like you're calling mysql_fetch_array(), or whichever fetch you're using, once before you enter a while loop, but since you didn't post that part of the code, it's kind of hard to be sure.

It sounds like you're calling mysql_fetch_array(), or whichever fetch you're using, once before you enter a while loop, but since you didn't post that part of the code, it's kind of hard to be sure.

 

correct was calling  mysql_fetch_array()  before loop,  see my post above as i've edited it

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.