help in php

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
User avatar
forgun
Forum Commoner
Posts: 61
Joined: Wed Jan 29, 2003 6:05 am
Contact:

help in php

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

Post 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?
User avatar
forgun
Forum Commoner
Posts: 61
Joined: Wed Jan 29, 2003 6:05 am
Contact:

Post by forgun »

Resource id #2
that is what is give me what's mean dont know
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
forgun
Forum Commoner
Posts: 61
Joined: Wed Jan 29, 2003 6:05 am
Contact:

Post by forgun »

the select is good its give 1
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

then the next step is

Code: Select all

...
print_r($display);
return $display;
}
pootergeist
Forum Contributor
Posts: 273
Joined: Thu Feb 27, 2003 7:22 am
Location: UK

Post 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.
Post Reply