php - A mysql query from multiple tables without anything in common -
edit: sorry guys, didn't knew can 3 select queries on same page that, thought limit 1 query/page , not 1 type of query/page. i've solved problem dividing multiple queries, question still remain (just out of curiosity): possible query multiple tables without when clause connects tables and without getting cartesian product?
thanks replies, many "divide multiple queries" replies made me "what if...is easy?" :). original question below:
i'm pretty new mqsql , ran obnoxious cartesian product. i'm trying query 3 tables don't have column in common (actually there connection between second , third table, ignore it). i've got tables t1(c1,c2,c3), t2(c4,c5), t3(c6,c7) , like:
$query="select * t1, t2, t3"; $request= mysql_query($query); $row = mysql_fetch_array($query); $i=0; while ($row = mysql_fetch_array($request)) { $array1[$i]=$row['c1']; $array2[$i]=$row['c2']; $array3[$i]=$row['c3']; $array4[$i]=$row['c4']; $array5[$i]=$row['c5']; $value6=$row['c6'][1]; $value7=$row['c7'][1]; $i++; }
all want arrays 1-7 on same php page (without adding framesets/frames ecc.)? i've tried breaking in multiple queries after guy's example http://www.dev-explorer.com/articles/multiple-mysql-queries didn't work.
edit: example data
table1:
---------------------------- fruit_id | f_name | f_color ---------------------------- 1 | apple | red 2 | banana | yellow
table2:
---------------------------- player_id | player_name ---------------------------- 1 | john 2 | scott 3 | mike 4 | george
table3:
---------------------------- other_id | other_name ---------------------------- 1 | alex
i want able in same page arrays $fruit_id values ['1','2'], $f_name ['apple','banana'], $f_color ['red','green'], $player_id['1','2','3','4'] ecc..
it not have mysql, long arrays.
what doing in example performing cartesian product of 3 tables. means every combination of tuples contained in 3 tables displayed.
this not looking for, should have @ joins, limit number of rows.
mysql supports set operations union if want venture in more complicated , nested queries. advice sticking joins
if data not connected in way, try issuing multiple queries (without trying fit 1 single sql statement), , output data manually in whichever form want display them.
whithout more information you're doing, cannot give other advice
Comments
Post a Comment