Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-14-2012, 06:53 PM   PM User | #1
cloudstryphe
New Coder

 
Join Date: Mar 2012
Posts: 63
Thanks: 7
Thanked 0 Times in 0 Posts
cloudstryphe is an unknown quantity at this point
Returning only 1 row

Hello all,

I'm running an sql query that joins 2 tables for stock information.

Table 1 has user id's and stock ids, table 2 has stockids and stock information.

I joined the tables so that I could query the stock information where the users have the stock id's

Code:
$query="SELECT `cosymbol` FROM `app_stockslist` 
		INNER JOIN `user_stocks` ON app_stockslist.stockid = user_stocks.stockid WHERE `userid`='$userid'";
$result=mysql_query($query) or die(mysql_error());
$array=mysql_fetch_array($result);
print_r($array);
When I run this exact same query in the PHPMyAdmin interface, it will return however number of rows correspond with the userid. When I run it via php on my webpage, it always just returns one row. Any Ideas?
cloudstryphe is offline   Reply With Quote
Old 09-14-2012, 08:00 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,751
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
You haven't done anything to loop your results. Pulling mysql_fetch_* functions only pull a single record and put them into an array, and then increment the pointer of the resultset to the next row. You need to pull multiple with a loop:
PHP Code:
while ($row mysql_fetch_assoc($result))
{
    
print_r($row);

Fou-Lu is offline   Reply With Quote
Old 09-14-2012, 08:14 PM   PM User | #3
cloudstryphe
New Coder

 
Join Date: Mar 2012
Posts: 63
Thanks: 7
Thanked 0 Times in 0 Posts
cloudstryphe is an unknown quantity at this point
Thank you. I knew it was something easy that I was looking over.
cloudstryphe is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:13 PM.


Advertisement
Log in to turn off these ads.