Page 1 of 1

join

Posted: Fri Jan 05, 2007 7:30 am
by kpraman
Hello,


Code: Select all

$query=mysql_query("SELECT * FROM categories,events,story");
	  while($r=mysql_fetch_array($query))
	    {
		  $catId[]=$r['categoryId'];
		}
print_r($catId);
The categories contains categoryId field , two rows have been populated. I am getting,

Code: Select all

Array ( [0] => 1 [1] => 2 [2] => 1 [3] => 2 [4] => 1 [5] => 2 [6] => 1 [7] => 2 [8] => 1 [9] => 2 [10] => 1 [11] => 2 [12] => 1 [13] => 2 [14] => 1 [15] => 2 [16] => 1 [17] => 2 [18] => 1 [19] => 2 [20] => 1 [21] => 2 [22] => 1 [23] => 2 [24] => 1 [25] => 2 [26] => 1 [27] => 2 [28] => 1 [29] => 2 [30] => 1 [31] => 2 )
I should get,

Code: Select all

Array ( [0] => 1 [1] => 2 [2]

Posted: Fri Jan 05, 2007 7:53 am
by volka
If you only want the two entries from one table why do you use a join with another table?

Re: join

Posted: Fri Jan 05, 2007 2:00 pm
by xpgeek
kpraman wrote:Hello,


Code: Select all

$query=mysql_query("SELECT * FROM categories,events,story");
	  while($r=mysql_fetch_array($query))
	    {
		  $catId[]=$r['categoryId'];
		}
print_r($catId);
try this

[sql]
SELECT * FROM categories,events,story LIMIT 2
[/sql]

Posted: Sat Jan 06, 2007 6:21 pm
by kpraman
Volka, in the while loop i'll be fetching other fields also from table2 and table3