Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Error while trying to display news
Old 11-27-2005, 03:49 AM Error while trying to display news
Ickie's Avatar
Extreme Talker

Posts: 217
Location: Australia
Trades: 0
Quote:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/ickius/public_html/news.php on line 5
PHP Code:
<? 
mysql_connect
("localhost","-","-");
mysql_select_db("-");

while(
$r=mysql_fetch_array(mysql_query("SELECT * FROM news ORDER BY id DESC"))) {
$title=$r["title"];
$date=$r["date"];
$name=$r["name"];
$story=$r["story"];

echo 
"<h1>$title</h1>\n";
echo 
"<p>$date posted by $name</p>\n";
echo 
"<p>$story</p>\n";
echo 
"<br />\n";
}
?>
What could be wrong? I'm so confused, it used to work fine.
Ickie is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-27-2005, 07:55 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
BEcause you've wrapped up the mysql_query() call inside the while loop condition, it is creating a new query and a new result set every time round. Try this:

PHP Code:
<? 
mysql_connect
("localhost","-","-");
mysql_select_db("-");

$result mysql_query("SELECT * FROM news ORDER BY id DESC") or die(mysql_error());

while(
$r=mysql_fetch_array($result)) {
$title=$r["title"];
$date=$r["date"];
$name=$r["name"];
$story=$r["story"];

echo 
"<h1>$title</h1>\n";
echo 
"<p>$date posted by $name</p>\n";
echo 
"<p>$story</p>\n";
echo 
"<br />\n";
}
?>
This way you will step through the results one by one rather than always getting the first line of a new result set. The error message you are getting usually indicates that your query is failing for some reason. The call to mysql_error() should print the MySQL error and tell you why it is failing.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 11-27-2005, 07:28 PM
Ickie's Avatar
Extreme Talker

Posts: 217
Location: Australia
Trades: 0
It says no database selected...? What's that mean, I've selected the database already.
Edit: Don't worry, I think it mite something with my host.

Last edited by Ickie; 11-28-2005 at 01:56 AM..
Ickie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Error while trying to display news
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.47571 seconds with 12 queries