1

this is my code. i want to echo both name and family service provider and customer together by fetching from one database, first by fetching name and family service_provider and then by fetching name and family customer.

  <?php
$id=$fgmembersite->UserID(); 

/* echo "$id"; */


$db_host = 'localhost';
$db_name= 'site';
$db_table= 'action';
$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 as service_name,
                              tablesite.family as service_family,
                              tablesite.username,
                              tablesite.phone_number,
                              tablesite.email,
                              action.service_provider_comment,
                              action.customer_comment,
                              action.price,
                              action.date,
                              job_list.job_name,
                              action.ind
                       FROM  $db_table
                       INNER JOIN job_list
                       on job_list.job_id=action.job_id 
                       INNER JOIN tablesite
                       on tablesite.id_user=action.service_provider_id
                       WHERE vote!=''
                       
                       UNION
                       
                   
                       SELECT tablesite.name as customer_name,
                              tablesite.family as customer_family
                       FROM  $db_table
                       INNER JOIN job_list
                       on job_list.job_id=action.job_id 
                       INNER JOIN tablesite
                       on tablesite.id_user=action.customer_id
                       WHERE vote!=''",$con);                      

                       
   $i = 1;
                               
                       while($amch=mysql_fetch_assoc($dbresult))

{?>
  <?php

echo "<form id='form_$i' method='post' action='{$_SERVER['PHP_SELF']}' accept-charset='UTF-8'>\r\n";
echo'<div dir="rtl">';
echo "نام خدمت دهنده: "."&nbsp&nbsp&nbsp".$amch["service_name"]." ".$amch["service_family"]."&nbsp&nbsp&nbsp"."شماره تماس: ".$amch["phone_number"]."&nbsp&nbsp&nbsp"."ایمیل: ".$amch["email"].'<br>'.

"شغل انجام شده: ".$amch["job_name"].'<br>'
."تاریخ انجام عملیات: ".$amch["date"].'<br>'
."هزینه ی کار: ".$amch["price"]." تومان".'<br>'
."توضیحات خدمت دهنده".'<br>'."- ".$amch["service_provider_comment"].'<br>';

echo "نام خدمت گیرنده: ".$amch["customer_name"].$amch["customer_family"];
echo "پاسخ خدمت گیرنده".'<br>'."- ".$amch["customer_comment"].'<hr/>';
}
?>
            
</fieldset>

after running this code i have this problem:

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

table action:

enter image description here

part of table action that has information of service provider

enter image description here

SELECT tablesite.name as 'service_name',
                              tablesite.family as 'service_family',
                              tablesite.username,
                              tablesite.phone_number,
                              tablesite.email,
                              action.service_provider_comment,
                              action.customer_comment,
                              action.price,
                              action.date,
                              job_list.job_name,
                              action.ind
                       FROM  $db_table
                       INNER JOIN job_list
                       on job_list.job_id=action.job_id 
                       INNER JOIN tablesite
                       on tablesite.id_user=action.service_provider_id
                       WHERE vote!=''

part of table action that has information about customer:

enter image description here

SELECT tablesite.name as 'customer_name',
                              tablesite.family as 'customer_family'
                       FROM  action
                       INNER JOIN job_list
                       on job_list.job_id=action.job_id 
                       INNER JOIN tablesite
                       on tablesite.id_user=action.customer_id
                       WHERE vote!=''
Community
  • 1
  • 1
sammy
  • 717
  • 4
  • 13
  • It means $dbresult is false. Use parameterized queries and not string queries. – George Irimiciuc Nov 08 '15 at 11:56
  • @GeorgeIrimiciuc: how? – sammy Nov 08 '15 at 11:58
  • @sajad check the error you get using `mysql_error`. probably has something to do with `!=`which should be `<>` – Gal Sisso Nov 08 '15 at 12:26
  • @Gal: your answer is false – sammy Nov 08 '15 at 12:27
  • @sajad post the error you get from `mysql_error` ? – Gal Sisso Nov 08 '15 at 12:29
  • That's not what `UNION` is for. You can use a union when you have multiple queries returning the same column number and types, such as getting the same information but from multiple sources. You are fetching disparate information, which is not a candidate for `UNION`. – Tino Didriksen Nov 08 '15 at 12:55
  • @maytham-ɯɐɥıλɐɯ did u find the answer? i need to echo name and family of customer where i selected service_provider_ name and family – sammy Nov 08 '15 at 13:30
  • You really should not be writing code that relies on `mysql_` functions anymore. The MySQL extension has been deprecated for years and is about to be dropped in the upcoming PHP7 release later this year. Also see [Why shouldn't I use mysql_* functions in PHP?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). On an up-to-date server, this code has a life span of about 2 months. – Oldskool Nov 08 '15 at 14:09
  • @maytham-ɯɐɥıλɐɯ: are you online? – sammy Nov 08 '15 at 17:35
  • @sajad have you seen what TinoDidriksen wrote? if you `var_dump($dbresult);` right after the statement and before the while loop you will get false this is because your statement is not returning any thing and this is because `UNION` does not fit to your achievement. How to fix it is depending on what you want to do, it is a bit unclear for me right now. – Maytham Fahmi Nov 08 '15 at 17:51
  • @maytham-ɯɐɥıλɐɯ answer= boolean false. what is unclear? look in my action table i have id of both customer and service_provider. names of users are in tablesite so if i want to fetch name of both customers and service_providers so i need connect to tablesite. because 'name' is a common colmn in tablesite so i dont know how to fetch names of them :( it's clear now? – sammy Nov 08 '15 at 18:07
  • @look on end of my post. added pictures. when i union that tables, i get error – sammy Nov 08 '15 at 18:19
  • @sajad this is what I and Tino trying to say. You can not use UNION like this – Maytham Fahmi Nov 08 '15 at 18:22
  • @maytham-ɯɐɥıλɐɯ is there another way except union for solving my problem? – sammy Nov 08 '15 at 18:28
  • @ i got union is not true, just duplicating! if you got what i need please help me to solve my problem... – sammy Nov 08 '15 at 18:32
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/94545/discussion-between-sajad-and-maytham-mahiam). – sammy Nov 08 '15 at 18:43

0 Answers0