Page 1 of 1

help in php

Posted: Fri Mar 21, 2003 5:09 pm
by forgun
this code have a prob

Code: Select all

function newsflash() {
    $root = "./";
    include ($root . "comm.inc");
    $err = "";
    $display = array ( );
    include($root . $path['db'] .'dbs.' .$red);
    $lk = mysql_connect($serv,$user,$pass) or die ('Unable to do connection to the data base');
    mysql_select_db($dbname[0] ,$lk);
    $qur = "SELECT id,flash FROM newsflash ORDER BY id DESC LIMIT 0, 3";
    $res = mysql_query($qur) or die ("error on the db" . $err = mysql_error());
    while ($row = mysql_fetch_array($res)) {
        $display[] = $row['flash'];
    }
    return $display;
}
the prob is that the var $display is all the time null onm the db there is a data i guess that the query is on error but not error that display on the page
i need to ask u guys wtf not good here any thing i try give me the $display null no data get in the the var why is that there is any errors on the code???

Posted: Fri Mar 21, 2003 7:32 pm
by volka
what does

Code: Select all

$res = mysql_query($qur) or die ("error on the db" . $err = mysql_error());
print(mysql_num_rows($res));
	while ($row = mysql_fetch_array($res)) {
print?

Posted: Sat Mar 22, 2003 6:30 am
by forgun
Resource id #2
that is what is give me what's mean dont know

Posted: Sat Mar 22, 2003 7:56 am
by twigletmac
It sounds like it means you didn't use the code volka gave you - did you do:

Code: Select all

print(mysql_num_rows($res));
as that should give you a number.

Mac

Posted: Sat Mar 22, 2003 10:45 am
by forgun
the select is good its give 1

Posted: Sat Mar 22, 2003 12:05 pm
by volka
then the next step is

Code: Select all

...
print_r($display);
return $display;
}

Posted: Sat Mar 22, 2003 12:05 pm
by pootergeist
is $dbname[0] global within your function?

try echoing it as the first line

other than that, the code looks pretty good to me.