I would have to agree with Dan.
This sounds like you need to rethink your queries rather than restructure your code.
Maybe we could be a bit more specific if you showed us the queries you are using.
@dlite922
Technically not true.
A while loop doesn't take any arguments. It does execute a statement on every loop, however.
This statement can do whatever you want it to, for example:
-
$result1 = mysql_query("SELECT * FROM someTable");
-
$result2 = mysql_query("SELECT * FROM someOtherTable");
-
-
while(
-
($row1 = mysql_fetch_assoc($result1)) or
-
($row2 = mysql_fetch_assoc($result2))
-
) {
-
echo "From someTable:\n";
-
foreach($row1 as $_key => $_value) {
-
echo " - $_key = $_value\n";
-
}
-
echo "From someOtherTable:\n";
-
foreach($row2 as $_key => $_value) {
-
echo " - $_key = $_value\n";
-
}
-
}
-
This would run through two result objects, printing ever row of each one.
I wouldn't recommend using this tho, as there are much better alternatives.
Just pointing out the possibility :)
You can even execute simple programs within that statement, without adding anything to the actual code block.
For example:
-
<?php
-
while(
-
(($i++ or true) // Always adds 1 to $i and evaluates true
-
and print(" Row $i" . PHP_EOL)) // Prints a line.
-
and ($i < 10) // Breaks the loop once $i reaches 10
-
)
-
{
-
// An empty code block! :D
-
}
-
?>
-
This would loop from 1 to 10, printing a line to the output for every loop.
Again, not exactly something you would want to use in a real program, but you get the point.