Page 1 of 1

Passing array values/query results

Posted: Fri Feb 27, 2004 11:09 am
by Rhino_dna
I have a page which returns the results of a search and have added a links on the images displayed. Now, these links open a pop-up in which more detailed information about that record is displayed. I pass the selected record_id and re-access the table to get the record details in the popup. Everything is kewl.

Feeling a bit like Superman - I now would like to add 'previous' and 'next' links from the original query record_set in my little pop-up so the end user can scroll thru the results on my detail page (in the popup)

I was thinking that if I simply passed the entire record_set array using the same link i used to get the detail page, then I could just use the record_id to find my place in the array, and then generate the relative the next & prev links from there.

So I guess my question is;
If my code looks something like this....

$record_set=@mysql_query("SELECT RecordID,Name from MyTable WHERE blah blah blah.. ");
while($row = mysql_fetch_array($record_set)) {
$recordID= $row[0];
$Name= $row[1];


(some cool table layout stuff)

<a href="detailpage.php?recordID=$recordID&record_set=$record_set">$Name</a>

}

why wont it work?
I think i've figured out that I can't pass array values this way. But if not this way , How? :?

Posted: Fri Feb 27, 2004 11:30 am
by Weirdan
You can try to [php_man]serialize[/php_man] your array. It would produce very long links, though. Or loop through your recordset, gather all ids and pass them as comma separated list to popup window. It would be shorter. And keep in mind, that $record_set is of type #resource, and you need an array. Here is a little trick I used to use when I need an entire recordset in array:

Code: Select all

$res=mysql_query("SELECT * from something");
 while($q=mysql_fetch_assoc($res)) $records_array[]=$q;
 foreach($records_array as $record){
   // .... do something to record
 }
I call it prefetch.

Passing array values/query results

Posted: Fri Feb 27, 2004 2:29 pm
by Rhino_dna
Ok Thats real cool, thanks - now I have all the values to attach from the very 1st link, but I'm still having problems passing the array using that

<a href="detailpage.php?recordID=$recordID&record_set=$record_set">$Name</a>

Posted: Sat Feb 28, 2004 11:39 am
by Weirdan
Show us your modified code.

Perhaps it should go to posting guidelines: No code - no answer :D