Hi I need to use info from 2 tables. i use this code: $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 "; PHP: 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
You're probably better off using aliases in your sql query. SELECT 1.id id, 1.advertiser_id ad_id, a.id anotherId FROM .... Notice the (space)(alias name) after each column in your select.
i used this code: $sql2="SELECT l.id lid, l.advertiser_id advertiser, l.title title, l.url url, l.displayurl display, l.description desc, l.adult adult, l.keywords keywords, l.maxb maxb, a.id id, a.balance balance FROM listing l ,advertiser a WHERE keywords LIKE '%$keyword%' and balance > 5 and advertiser=lid ORDER BY maxb DESC LIMIT $lim "; PHP: it says: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc, l.adult adult, l.keywords keywords, l.maxb maxb, a.id id, where i am wrong?
anyway, using aliases or not, every fetch in your query is stored into an array and you can identify your field results by a numeric index, i.e., $row2[0] instead of $row2['id']