0

i'm working on my project and i want get name,family,phone_number and email from tablesite + job_name from job_list + comments from relation. this is my code:

  <fieldset class="fdex" >
        <legend><span class="style4">لیست مشاغل</span></legend>


        <?php

$db_host = 'localhost';
$db_name= 'site';
$db_table= 'tablesite';
$db_user = 'root';
$db_pass = '';




$con = mysql_connect($db_host,$db_user,$db_pass) or die("خطا در اتصال به پايگاه داده");
$selected=mysql_select_db($db_name, $con) or die("خطا در انتخاب پايگاه داده");
mysql_query("SET CHARACTER SET  utf8");

$dbresult=mysql_query("SELECT tablesite.name,
                          tablesite.family,
                          tablesite.phone_number,
                          tablesite.email,
                          job_list.job_name,
                   FROM  $db_table
                   INNER JOIN relation
                   on tablesite.id_user=relation.user_id
                   INNER JOIN job_list
                   on relation.job_id=job_list.job_id",$con);

while($amch=mysql_fetch_assoc($dbresult))
{?>

<?php
echo "* نام: "."&nbsp&nbsp&nbsp".$amch["tablesite.name"]." ".$amch["tablesite.family"]."&nbsp&nbsp&nbsp"."* عنوان خدمت: ".$amch["job_list.job_name"]."&nbsp&nbsp&nbsp"."* شماره تماس: ".$amch["tablesite.phone_number"]."&nbsp&nbsp&nbsp"."* ایمیل: ".$amch["tablesite.email"].'<br>'
.$amch["relation.comments"].'<br>';

}
?>

</fieldset>

when i run the code i have error:

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\wamp\www\source\JobList.php on line 259

line 259:

 while($amch=mysql_fetch_assoc($dbresult))

tablesite: id_user,name,family,phone_number,email

job_list: job_id, job_name

relation: job_id, user_id, comments

chris85
  • 23,591
  • 7
  • 30
  • 47
sammy
  • 719
  • 4
  • 13
  • Check for errors on the query execution. http://php.net/manual/en/function.mysql-error.php Also consider updating to `mysqli` or `pdo` in the future. – chris85 Oct 31 '15 at 17:33

1 Answers1

1

Your query has an extra comma that isnt needed, update your query to this:

SELECT tablesite.name,
                      tablesite.family,
                      tablesite.phone_number,
                      tablesite.email,
                      job_list.job_name //<--it was here
               FROM  $db_table
               INNER JOIN relation
               on tablesite.id_user=relation.user_id
               INNER JOIN job_list
               on relation.job_id=job_list.job_id

You also dont need to specify the table name in your php:

<?php
echo "* نام: "."&nbsp&nbsp&nbsp".$amch["name"]
."     ".$amch["family"]."&nbsp&nbsp&nbsp"."* عنوان خدمت:"
.$amch["job_name"]."&nbsp&nbsp&nbsp"."* شماره تماس:"
.$amch["phone_number"]."&nbsp&nbsp&nbsp"."* ایمیل:"
.$amch["email"].'<br>'.$amch["comments"].'<br>';

}
?>
Paul Stanley
  • 3,893
  • 6
  • 32
  • 51