Credit Cards - Loans - Free Advertising - Freelance - Anime

PDA

View Full Version : PHP Arrays


mich21
Feb 18th 2008, 12:13 am
I have an array of id's(array1) each with corresponding hits(array2).
Im using an imploded array1 to select ids from a table.

like so:
select * from table where id in $array1;


Now i want to add the corresponding hits of each id in the query result.

The problem is that the result is automatically ordered by id ASC. So when i add my hits to the result, they do not match with the id's. How can i achieve this? Thanks in advance :)

00johnny
Feb 18th 2008, 1:38 am
I like the idea of using one array so its more organized
ie
array(
id => value
);
is a typical setup that I use.
then you can loop through your results and find a match, sure this is slow but.. oh well


foreach($result as $r) {
foreach($hitArray as $h) {
if($r['id'] == $h['id']) {
// oh cool!, now $r is the row that has all your data and $h is your hit value
}
}

mich21
Feb 18th 2008, 2:41 am
thanks a lot! But I forgot to add that i'm using paging:

select * from table where id in $array1 $LIMIT;
$LIMIT = $LIMIT($a,$b);

I made it work without paging though.. :)