2

I am trying to join two tables and I'm stuck. The two tables have some rows with same name.

table1: shop 
rows: sid, typeid, name, email_id, url, logo, app_link, phone, status, username, password

table2: shopnews
rows: nid, typeid, sid, url, logo, start_date, end_date, add_date, name, short_detail, status, updated_on

What I'm trying to do is to get * from shopnews, name and url from shop where sid is the same in both tables.

I realy have no idea what I'm doing here, but here is part of my code:

  mysql_select_db($db, $con);
  $result = mysql_query("SELECT sid AS ssid, name AS ssname, url AS ssurl, logo AS sslogo, status AS sstatus FROM shop INNER JOIN shopnews ON shop.ssid = shopnews.sid"); 

  while($row = mysql_fetch_array($result))
  {
      $nid=$row['nid'];
      $typeid=$row['typeid'];
      $sid=$row['sid'];
      $shopname=$row['ssname'];
      $shopurl=$row['ssurl'];
      $url=$row['url'];
      $logo=$row['logo'];
      $start_date=$row['start_date'];
      $end_date=$row['end_date'];
      $add_date=$row['add_date'];
      $name=$row['name'];
      $short_detail=$row['short_detail'];
      $shopstatus=$row['sstatus'];
      $status=$row['status'];
  }

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given

Can some one tell me what I'm doing wrong?

Shoe
  • 74,840
  • 36
  • 166
  • 272
  • there must be sometype of error in your query. Thats why the query is not executed and $result has boolean false. Try to fire the same query in console or phpmyadmin, it will tell you the error. Moreover, you must select all the fields you want. Above, you have used nid(and many other fields) but you have not selected it in your query. – Bhavik Shah Dec 21 '12 at 11:24
  • Possible duplicate [mysql_fetch_array() expects parameter 1 to be resource, boolean given in select](http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in-select?answertab=votes#tab-top) – John Conde Dec 30 '12 at 05:18

1 Answers1

0

Try this:

SELECT sn.*, s.name ssname, s.url surl
FROM shop s INNER JOIN shopnews sn ON s.sid = sn.sid
Saharsh Shah
  • 28,687
  • 8
  • 48
  • 83