kenny22 Posted March 19, 2011 Share Posted March 19, 2011 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" /> Link to comment https://forums.phpfreaks.com/topic/231085-loop-through-returned-records-from-query/ Share on other sites More sharing options...
RussellReal Posted March 19, 2011 Share Posted March 19, 2011 inside the for loop.. throw this in there for($counter = 1;$counter<=$numberofrow;$counter++){ $row_Recordset1 = mysql_fetch_assoc($Recordset1); ?> Link to comment https://forums.phpfreaks.com/topic/231085-loop-through-returned-records-from-query/#findComment-1189469 Share on other sites More sharing options...
kenny22 Posted March 19, 2011 Author Share Posted March 19, 2011 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 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 Link to comment https://forums.phpfreaks.com/topic/231085-loop-through-returned-records-from-query/#findComment-1189549 Share on other sites More sharing options...
Pikachu2000 Posted March 19, 2011 Share Posted March 19, 2011 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. Link to comment https://forums.phpfreaks.com/topic/231085-loop-through-returned-records-from-query/#findComment-1189553 Share on other sites More sharing options...
kenny22 Posted March 19, 2011 Author Share Posted March 19, 2011 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 Link to comment https://forums.phpfreaks.com/topic/231085-loop-through-returned-records-from-query/#findComment-1189559 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.