Jump to content
php.lv forumi

query no 3 tabulām


euphoric

Recommended Posts

kodu paradi kas tev jau ir.

$query = array();
$query[] = "select * from tabula1 order by id desc limit 0,5";
$query[] = "select * from tabula2 order by id desc limit 0,5";
$query[] = "select * from tabula3 order by id desc limit 0,5";

foreach($query as $q){
$q = mysql_query($q);
while($array = mysql_fetch_array($q)){ $dati[] = $array; }
}

usort($dati);

// masiva $dati ir 15 ieraksti

 

 

protams ieteiktu tev lietot select ... left join ...

Edited by EdgarsA
Link to comment
Share on other sites

Varbūt par tādu metodi mani kāds sitīs, bet es izmantotu kaut ko tādu.

$q = mysql_query("SELECT t1.pedejais1 as p1 FROM tabula1 AS t1, t2.pedejais2 as p2 FROM tabula2 as t2, t3.pedejais3 as p3 FROM tabula3 as t3") or die(mysql_error());
$data = mysql_fetch_assoc($q);

un tad izvadi

echo $data['p1'];
echo $data['p2'];
echo $data['p3'];

Link to comment
Share on other sites

Varbūt par tādu metodi mani kāds sitīs, bet es izmantotu kaut ko tādu.

$q = mysql_query("SELECT t1.pedejais1 as p1 FROM tabula1 AS t1, t2.pedejais2 as p2 FROM tabula2 as t2, t3.pedejais3 as p3 FROM tabula3 as t3") or die(mysql_error());
$data = mysql_fetch_assoc($q);

labāk palasi, kā raksta sql SELECT http://dev.mysql.com/doc/refman/5.0/en/select.html

Edited by 2easy
Link to comment
Share on other sites

Ir nepieciešams izvadīt vienā vietā pedējos ierakstus no 3 dažādam tabulām

JOIN šajā gadījumā nederēs, pat ja tās 3x tabulas arī būtu savā starpā saistītas

vai nu UNION vai 3x SELECT

Edited by 2easy
Link to comment
Share on other sites

Dekarta reizinājums dod visu ierakstu kombinācijas. Ja no katras tabulas ir pa 1 ierakstam, tad 1*1*1 vienalga ir 1. Ziepes, protams, potenciāli sākas tad, ja kādā no iesaistītajām tabulām atlasa vairāk kā 1, bet tad jebkurā gadījumā būtu kļūda.

 

Gints Plivna

http://datubazes.wordpress.com

Link to comment
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...