I've run into a problem that I'm sure has been answered, but I don't have the experience to be able to find any solution.
I would like to be able to pull a lump of information from my MySQL database, and then use a function to sort information out of it. Unfortunately, I can't find anyway to allow my functions to reference a value that hasn't been passed to them, and I can't pass the results of the Database query several times.
ie:
$query = "select * from table order by id desc limit 250";
$result = mysql("database",$query);
function getinfo($field1,$field2) {
while ($data = mysql_fetch_array($result)) { etc. etc. }
}
Gives me an invalid MySQL resource complaint against $result in the function. Alternatively, if I try to change the function to getinfo($field1,$field2,$mysqlarray) { } then the second time I run the function the $result variable is completely toasted. The entire point of my trying to rewrite this (Which is extremely difficult to explain, although it makes sense in MY head. 🙂 ) is to minimize SQL queries. Is there anyway to maintain the integrity of that $result array without requerying? I've tried $resultbak = $result, and it doesn't help. 🙁
If you need more information, I'll do my best to clarify.