Jump to content
echah

Inner Join 2 Tables....

Recommended Posts

<html>

<head>

<?php

$username=$_POST["txtUsername"];

$password=$_POST["txtPassword"];

//connect to mysql server

$db=mysql_connect("localhost","","")

or die

("could not connect to database, please check that mysql is running");

mysql_select_db("foxboro2");//database name

$query=SELECT staff.Staff_ID, computer.computer_ID, computer.type, computer.Model, software.software_type, software.Description, software.Serial_Number

FROM (staff LEFT JOIN computer ON staff.Staff_ID=computer.Staff_ID) LEFT JOIN software ON computer.computer_ID=software.computer_ID;";

$result=mysql_query($query);

$num_rows=mysql_num_rows($result);

?>

<title>AddressBook:View Data</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>

<? if ($num_rows>0){ ?>

<table width="98%" border="1">

<tr>

<td width="2%">&nbsp;</td>

<td width="31%">Staff ID</td>

<td width="19%">Computer ID</td>

<td width="31%">Type</td>

<td width="19%">Model</td>

<td width="31%">Software type</td>

<td width="19%">Description</td>

<td width="31%">Serial number</td>

</tr>

<? for($i=1;$i<=$num_rows;$i++){

$row=mysql_fetch_array($result); ?>

<tr>

<td><? echo $i?></td>

<td><? echo $row["Staff_ID]?></td>

<td><? echo $row["computer_ID"]?></td>

<td><? echo $row["type"]?></td>

<td><? echo $row["Model"]?></td>

<td><? echo $row["software_type"]?></td>

<td><? echo $row["Description"]?></td>

<td><? echo $row["Serial_Number"]?></td>

</tr>

<? }//end for

} //end if

else{ ?>

There is no record to show.....

<? }//end else?>

</table>

<p>&nbsp;</p>

</body>

</html>

nape table inner join tu xleh disply ek...die akan kuar 'There is no record to show.....'

tolong r bantu sy..buntu dah ni...mencr syntax...

Share this post


Link to post
Share on other sites

sepatutnya ada record ker ?

sebelum tuh,mmg awak kena tahu dulu bagaimana relation antara semua table tu. one-to-one,one-to-many ?

maybe echah boleh tolong display sample data from table :

1. Staff

2. Computer

3. Software

baru senang utk kawan2 lain tengok. :)

begheh.

Edited by arejae

Share this post


Link to post
Share on other sites

sy dah berjaya wat inner join tu cz sy lupe nk key in data dlm tables..hihihi..malu jek...and one more thing i want to ask u...cm ne ek coding utk insert, delete, edit table gune coding inner join tu...ade syntax r...tolong ek..

Share this post


Link to post
Share on other sites

join dipakai utk select statement je rasenye..

kalo nk insert,update or delete kna wat utk satu2 table..tp taktaula kot2 boleh..

tp x susah pn sbb dia akan ada id yg sama..

so based on id tu la kite delete or update..

snarnye yg joinkn antara 2 or lebih table tu based on id yg sama je..

Share this post


Link to post
Share on other sites

syntax utk SQL...sy gune coding yg same utk view dgn coding inner join..and mcm xleh gune lak coding tu generate ke coding utk insert, delete an so on...

Share this post


Link to post
Share on other sites

join dipakai utk select statement je rasenye..

kalo nk insert,update or delete kna wat utk satu2 table..tp taktaula kot2 boleh..

tp x susah pn sbb dia akan ada id yg sama..

so based on id tu la kite delete or update..

snarnye yg joinkn antara 2 or lebih table tu based on id yg sama je..

memg kena gune base yg same kan....dah try r...n sush skit...coding jd panjg giler...so for exmple if kite nk insert data so dua2 table pun berubah sekali....utk view sy dah wat nn blh run utk stemant yg lain tu r..sush skit....

Share this post


Link to post
Share on other sites

syntax utk SQL...sy gune coding yg same utk view dgn coding inner join..and mcm xleh gune lak coding tu generate ke coding utk insert, delete an so on...

sebenarnya join ke tak join ker...kita punya tujuan nak view result kan. means,still lagi kita guna select statement. kalau utk delete,insert,update kita kenalah pakai specific statement utk tujuan2 tuh. err...tak tahulah menjawab soklan ke idak.

ermm..nampak macam awak nak buat address book nyer application kan. (based on awak nyer <title>) apa kata kalau cuba usha kat sini caner derang buat.

http://php.about.com/od/finishedphp1/ss/address_book.htm

Share this post


Link to post
Share on other sites

sebenarnya join ke tak join ker...kita punya tujuan nak view result kan. means,still lagi kita guna select statement. kalau utk delete,insert,update kita kenalah pakai specific statement utk tujuan2 tuh. err...tak tahulah menjawab soklan ke idak.

ermm..nampak macam awak nak buat address book nyer application kan. (based on awak nyer <title>) apa kata kalau cuba usha kat sini caner derang buat.

http://php.about.com/od/finishedphp1/ss/address_book.htm

ops..bukan address book...hihih...lupe lak nk update...nk wat database utk staff company ni...ok..thank a lot byk gak membantu...hihih...one more thing is, if kite nk join table kan gune one to many.*contoh 1 staff ade dua computer laptop n desktop so die punye coding tu kan kite leh wat jgk ke kt PHP mysql tu???confius r....ihihihi..byk lak soalan kt awk....sory...sy bru nk blaja...

Share this post


Link to post
Share on other sites

Bukan join table ni untuk merge table ker.

tapi dulu aku pernah pernah menggabungkan pelajar yang berada di 2 blok berasingan tetapi sama tingkatan.

tujuan aku join table utk gabungkan pelajar yang sama tingkatan di query yang aku nak.

malangnya aku da lama tak sentuh mysql.

yang aku ingat cuma apa yang dipratikkan dan ianya terhasil.

maaf, cuma berkongsi pengalaman.

Share this post


Link to post
Share on other sites

Bukan join table ni untuk merge table ker.

tapi dulu aku pernah pernah menggabungkan pelajar yang berada di 2 blok berasingan tetapi sama tingkatan.

tujuan aku join table utk gabungkan pelajar yang sama tingkatan di query yang aku nak.

malangnya aku da lama tak sentuh mysql.

yang aku ingat cuma apa yang dipratikkan dan ianya terhasil.

maaf, cuma berkongsi pengalaman.

memg utk marge table...untuk view sy dah dpt coding die...masalah skrg utk edit, update, insert...tu problem skit dgn coding die...st try wat...tp syntax r...tu yg nk tau coding tuk marge table ni leh ke wat utk edit, update, insert tu??

Share this post


Link to post
Share on other sites

join mainly for retrieving records dari database... kalau tuk insert or update, u kena specify table tu satu persatu... condition nye, u may change tapi bukan the insert or update statement...

contoh - something cenggini lar...:

insert into table A (select from table c ......)

tapi kalau dari form, memang kena insert satu2... sebab awak ada master and detail table.. so, master memang kena insert dulu.. then baru detail...

Share this post


Link to post
Share on other sites

join mainly for retrieving records dari database... kalau tuk insert or update, u kena specify table tu satu persatu... condition nye, u may change tapi bukan the insert or update statement...

contoh - something cenggini lar...:

insert into table A (select from table c ......)

tapi kalau dari form, memang kena insert satu2... sebab awak ada master and detail table.. so, master memang kena insert dulu.. then baru detail...

ooo...mksdnye

contoh:

table 1: staff

table 2: hardware

above statement ade 2 table....so if nk insert, update n delete kena one by one r insert n change ek....xleh dr table staff and hrdware yg dah combine tu kite change or insert??

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...