Page 1 of 1

selecting from more than 1 table

Posted: Mon Aug 27, 2007 7:57 am
by m2babaey
Hi
I need to use info from 2 tables. i use this code:

Code: Select all

$sql2="SELECT l.id , l.advertiser_id , l.title , l.url , l.displayurl , l.description , l.adult , l.keywords , l.maxb , a.id , a.balance FROM listing l ,advertiser a WHERE keywords LIKE '%$keyword%' and a.balance>5 and l.advertiser_id=a.id ORDER BY maxb DESC  LIMIT $lim ";
then i need to use mysql_fech_array you know.
$row2=mysql_fetch_array($result2)
then how should i specify array elements?
we used $listing=$row2['id']; what now? when i use $listing=$row2['l.id']; it seems not working

Posted: Mon Aug 27, 2007 8:02 am
by xpgeek
mysql_fetch_array - return indexed array, you have to use $row[0], $row[1] and os on
also you can use
mysql_fetch_assoc - return indexed and associative array

Read all about mysql functions on http://php.net/mysql

Posted: Mon Aug 27, 2007 11:54 am
by miro_igov
mysql_fetch_array - return indexed and associative array - $row[0],$row['id'],$row[1],$row['advertiser_id'] ...
mysql_fetch_assoc - return associative array - $row['id'], $row['advertiser_id'] ...

Posted: Mon Aug 27, 2007 12:57 pm
by xpgeek
miro_igov wrote:mysql_fetch_array - return indexed and associative array - $row[0],$row['id'],$row[1],$row['advertiser_id'] ...
mysql_fetch_assoc - return associative array - $row['id'], $row['advertiser_id'] ...
It is not true!
By default mysql_fetch_array dos not fetch results as associative array only as indexed array.
Also mysql_fetch_assoc fetch results as associative and indexed array by default parameters.

Posted: Mon Aug 27, 2007 4:00 pm
by feyd
Hmm... miro_igov is correct xpgeek.

Posted: Mon Aug 27, 2007 5:23 pm
by xpgeek
Sorry miro_igov, my bad - second parameter of mysql_fetch_array is MYSQL_BOTH by default - it is indexed and associative type of array.