join

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

join

Post 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]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

If you only want the two entries from one table why do you use a join with another table?
User avatar
xpgeek
Forum Contributor
Posts: 146
Joined: Mon May 22, 2006 1:45 am
Location: Kyiv, Ukraine
Contact:

Re: join

Post 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]
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

Post by kpraman »

Volka, in the while loop i'll be fetching other fields also from table2 and table3
Post Reply