Closed Thread Icon

Topic awaiting preservation: Run loop through query results several times? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=11951" title="Pages that link to Topic awaiting preservation: Run loop through query results several times? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Run loop through query results several times? <span class="small">(Page 1 of 1)</span>\

 
Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 12-11-2001 20:52

Let's see if I can explain this so that it makes sense.

I have a JavaScript script that goes like this:
var messageurl = new Array()
messageurl[0]="http://www.blah.com/link1"
messageurl[1]="http://www.blah.com/link2"
messageurl[2]="http://www.blah.com/link3"

var messageimg = new Array()
messageimg[0]="blah.jpg"
messageimg[1]="blah2.jpg"
messageimg[2]="blah3.jpg"

and so on, with several other arrays

Now, i want to retrieve the data for those arrays from MySQL. My question is, can I retrieve all of the info at one time ("select * from...."), and then loop once through the results to populate messageurl, then loop through the results again to populate messageimg, etc? Each row in the DB would include one of each (messageimg, messageurl, etc)

Of should I do a select statement for each array, and loop that way? Obviously, multiple select statements isn't what I want to do. But if it's the only way.....

Tips? Suggestions? Death Threats?

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-11-2001 21:00

why cant you set both variables in one loop?

begin loop
messageurl[i]=row[data1]
messageimg[i]=row[data2]
end loop



Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 12-11-2001 21:19

Pugzly: If I understand the question (I'm not on form today) then perhaps this might be what you are looking for:
www.gurusnetwork.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=20&t=000020

You could use one select to grab all the data and load them into arrays and then spit the contents out as you require them. I think that might help cut down the hits the DB gets.

Emps


You're my wife now Dave

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 12-11-2001 21:26

Pugzly, you can do both things in one loop like Grumble said... But, if you don't want to mix those JS arrays (in order to improve readability), you can do something like this:

$array_str1 = ""; $array_str2 = "";

while ($row = mysql_fetch_array()) {
&nbsp;&nbsp;&nbsp;&nbsp;$array_str1 .= "blahblah1[index] = $row[field1]\n"; // first JS array
&nbsp;&nbsp;&nbsp;&nbsp;$array_str2 .= "blahblah2[index] = $row[field2]\n"; // second JS array
}

print $array_str1; // print first JS array
print $array_str2; // print second JS array




[This message has been edited by mr.maX (edited 12-11-2001).]

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 12-11-2001 22:28

Um but yeah you can loop through twice



:[ Computers let you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila. ]:

« BackwardsOnwards »

Show Forum Drop Down Menu