Jump to content

loop through same record set twice


chelnov63

Recommended Posts

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

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'];	
                        }	
              }

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.