Page 1 of 1

how to join the tables?

Posted: Sat Feb 04, 2006 9:26 pm
by ashrafzia
how can i apply join query in the following code? as i want to display all records from the table. Currently i am getting records from the table but with reptition. I have 2 records but 8 records are retrieving with repitition of previous.

Code: Select all

include "conn.php";
echo "<table border=1>";
$sql="select *  from data, proj_analysis, ser_req";
$result=mysql_query($sql,$conn) or die (mysql_error());
while ($row=mysql_fetch_array($result))
{
 $id=$row['c_id'];
 $uname=$row['name'];
 $pdesc=$row['p_desc'];
 $deadline=$row['deadline'];
 $budget=$row['exp_budget'];
 $fwb=$row['FWB'];
 $res=$row['REs'];
 $wm=$row['WM'];
 $sd=$row['SD'];
 $gd=$row['GD'];
 $dd=$row['3D'];
 $fp=$row['FP'];
 $ew=$row['EW'];
 $sc=$row['SC'];
 $opi=$row['OPI'];
 $est=$row['EST'];
 $aai=$row['AAI'];
 $ddw=$row['DDw'];
 $no=$row['c_number'];
 $email_id=$row['email'];
 
 echo " <tr>
	<td width=\"171\">Customer ID : </td>
	<td width=\"182\">$id&nbsp</td>
  </tr>
  <tr>
	<td>Name : </td>
	<td>$uname&nbsp</td>
  </tr>
  <tr>
	<td>Phone Number : </td>
	<td>$no&nbsp</td>
  </tr>
  <tr>
	<td>E-mail Address : </td>
	<td>$email_id&nbsp</td>
  </tr>
  <tr>
	<td>Product Description : </td>
	<td>$pdesc&nbsp</td>
  </tr>
  <tr>
	<td>Deadline : </td>
	<td>$deadline&nbsp</td>
  </tr>
  <tr>
	<td>Budget : </td>
	<td>$budget&nbsp</td>
  </tr>
  <tr>
	<td>Services Required : </td>
	<td>$fwb <br> $res <br> $wm <br> $sd <br> $gd <br> $dd <br> $fp <br> $ew <br> $sc <br> $opi <br> $est <br> $aai <br> $ddw <br></td>
  </tr>";   
 
}

echo "</table>";

Posted: Sat Feb 04, 2006 9:30 pm
by feyd
you're using an implicit inner join with no limitations on record matching. You need to add a WHERE clause that locks records together to form the record you wish them to be.

http://dev.mysql.com/doc/refman/4.1/en/join.html

THnx

Posted: Sat Feb 04, 2006 9:38 pm
by ashrafzia
I really don't remeber to put condition in the query . it's working now.
I change the query to :

Code: Select all

$sql="select *  from data, proj_analysis, ser_req where data.c_id=proj_analysis.c_id && data.c_id=ser_req.c_id";
Now i want just to display the names from the table and then by clicking on the names of the person like hyperlink i want to view there records . I don't know how to do that. can any body help me?