selecting from more than 1 table

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

selecting from more than 1 table

Post 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
User avatar
xpgeek
Forum Contributor
Posts: 146
Joined: Mon May 22, 2006 1:45 am
Location: Kyiv, Ukraine
Contact:

Post 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
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post 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'] ...
User avatar
xpgeek
Forum Contributor
Posts: 146
Joined: Mon May 22, 2006 1:45 am
Location: Kyiv, Ukraine
Contact:

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Hmm... miro_igov is correct xpgeek.
User avatar
xpgeek
Forum Contributor
Posts: 146
Joined: Mon May 22, 2006 1:45 am
Location: Kyiv, Ukraine
Contact:

Post 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.
Post Reply