chelnov63 Posted May 28, 2009 Share Posted May 28, 2009 hi suppose i have a recordset and loop through it. Now suppose i wanted to again loop through the exact same recordset..how do i go back to index zero of the recordset and loop through it again: <?php $result_contacts = mysql_query("SELECT * FROM contacts"); while ($row = mysql_fetch_assoc($result_contacts)) { echo $row["surname"]."<br>"; } echo "----------------------"; //the following does not show any results..how do i set the recordset back to zero? while ($row = mysql_fetch_assoc($result_contacts)) { echo $row["surname"]."<br>"; } ?> Thanks in advance for your help Link to comment https://forums.phpfreaks.com/topic/160006-loop-through-same-record-set-twice/ Share on other sites More sharing options...
kickstart Posted May 28, 2009 Share Posted May 28, 2009 Hi Probably reset the internal record pointer using mysql_data_seek All the best Keith Link to comment https://forums.phpfreaks.com/topic/160006-loop-through-same-record-set-twice/#findComment-844038 Share on other sites More sharing options...
joesaddigh Posted May 28, 2009 Share Posted May 28, 2009 You could use a for loop to do this... //Loop through the links and get the value and populate the array for($link=1; $link<=$totalwelcomelinks; $link+=1) { //Prepare the query $querylanguage= "SELECT language.LanguageID, language.Language, languagepage.LanguageID, languagepage.PageID, languagepage.Section, languagepage.Text FROM language INNER JOIN languagepage ON language.LanguageID = languagepage.LanguageID WHERE languagepage.LanguageID = '$languageid' AND languagepage.PageID = 11 AND languagepage.Section = '$link'"; //Perform the query $resultlanguage = mysql_query($querylanguage, $conn) or die ("The join query is not working"); //Use the link variable to get the number of the link in order to assign the relevant path while($row= mysql_fetch_array($resultlanguage)) { $languagetext = $row['Text']; } } Link to comment https://forums.phpfreaks.com/topic/160006-loop-through-same-record-set-twice/#findComment-844039 Share on other sites More sharing options...
chelnov63 Posted May 28, 2009 Author Share Posted May 28, 2009 awesome thanks kickstart, works perfect!! ... joe think you replied to me by accident? Link to comment https://forums.phpfreaks.com/topic/160006-loop-through-same-record-set-twice/#findComment-844047 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.