Database Query to populate an array()
Posted: Sun Jul 27, 2008 4:46 pm
Ok here's another one from me! I'm learning an unbelievable amount!
So what I would like to do is populate an array() or something of the sort by a database query
example shown below:
What I need to do is populate an array to be used in a "for each loop" that will be used for another database query. Can you do a database query to act like a while loop in a for each loop?
So I want to do something like this later on in the code:
What happens is, the array only stores the first result but doesn't store all the results. I am sure I can get this to work if I can figure out how to populate that array with all the results. Maybe I'm using the wrong function (which is very possible knowing me).
Thanks!!!
So what I would like to do is populate an array() or something of the sort by a database query
example shown below:
Code: Select all
$sql='SELECT * from streams JOIN link ON link.streamid=streams.streamid WHERE streams.streamtype = 2 AND link.uid = "'.$uid.'" AND link.sticky <> "" ORDER BY streams.streamid ASC';
$result=mysql_query($sql) or die("Query failed " . mysql_error());
$counter = 0;
while($row=mysql_fetch_assoc($result)) {
[b]$streamno = array($row['streamid']);[/b]
//rest of while loop
So I want to do something like this later on in the code:
Code: Select all
[b]foreach ($streamno as $stream)[/b] {
$sql='SELECT * from streams where streamtype = 2 AND streamid <> "'.[b]$stream[/b].'" ORDER BY streamid ASC';
$result=mysql_query($sql) or die("Query failed " . mysql_error());
$counter = 0;
while($row=mysql_fetch_assoc($result)) {
//rest of while loop
Thanks!!!