Reputation: 51
I have two mysql_queries who have two while loops in fetch_assoc. One written inside another. I want to take one while loop inside a function and another inside another function. How to do that? Help. Here's an example of what I'm trying to say.
$query1 = mysql_query('...');
while($row1 = mysql_fetch_assoc($query1)){
$id = $row1['id'];
$query2 = mysql_query('...');
while($row2 = mysql_fetch_assoc($query2)){
$picture = $row2['picture'];
echo $id.' '.$picture;
} }
I want to take these two inside two different functions..
function query1(){
1st query with 1st while loop
}
function query2(){
2nd query with 2nd while loop
}
So that I can execute them just the way it is supposed to be..
query1();
query2();
echo $id.' '.$picture;
How to achieve this? Help.
Upvotes: 0
Views: 82
Reputation: 770
You could structure it as follows:
function query2(){
//do inner stuff
}
function query1(){
//do stuff
query2();
}
query1();
Let me know if you need more context!
Upvotes: 1