CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   MySQL (http://www.codingforums.com/forumdisplay.php?f=7)
-   -   Returning only 1 row (http://www.codingforums.com/showthread.php?t=273146)

cloudstryphe 09-14-2012 06:53 PM

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?

Fou-Lu 09-14-2012 08:00 PM

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);



cloudstryphe 09-14-2012 08:14 PM

Thank you. I knew it was something easy that I was looking over.


All times are GMT +1. The time now is 06:43 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.