Page 1 of 1

Pulling a result from database

Posted: Mon Apr 21, 2008 7:18 am
by arunkar
Hi all,

I'm fairly new to PHP. I'm not sure what is going wrong.

I have a very simple sql that is returning a result on the database. but when I use a php to pull the data. its not showing any result.

THis is the code:

Code: Select all

 
$result = mysql_query("Select subscriberid from SendStudio_list_subscribers where formid=5 order by subscriberid desc");
 
 if ($row = mysql_fetch_row($result)) {
        print "$CartID: ".$row." ";
        } else {
           print (mysql_error());
        }
 
    print "$CartID: ".$CartID." ";
 
exit();
 
The output I get for this code is: : Array : strange I dont know why.
So I tried the another methord:

Code: Select all

 
$result = mysql_query("Select subscriberid from SendStudio_list_subscribers where formid=5 order by subscriberid desc");
 
while($r=mysql_fetch_row($result))
{   
    $CartID = $r["subscriberid"];
    echo "$CartID: ".$CartID." ";
}
    print "$CartID: ".$CartID." ";
 
exit();
 
 
Nothing gets displayed for the above code.

when I try this sql

Code: Select all

 
Select subscriberid from SendStudio_list_subscribers where formid=5 order by subscriberid desc
 
on mysql db I get the output as I know there is a record. :banghead:

what is the wrong... can some one spot the mistake...

thanks :)

Re: Pulling a result from database

Posted: Mon Apr 21, 2008 7:25 am
by John Cartwright
mysql_fetch_row() returns an array of the current row. Your likely after $row[0].. although I would recommend using mysql_fetch_assoc() so you may reference your columns associatively, i.e. $row['subscriberid']

take a look at http://php.net/arrays on how to handle arrays

Re: Pulling a result from database

Posted: Mon Apr 21, 2008 11:29 am
by arunkar
Thanks Jcart....

:D cheers