PHP: Looping
Okay basically I'm getting an error and I don't know why. Maybe you guys can help me?
here is my code:
<?php
while($row = mysql_fetch_array($news)) {
// stuff goes here
}
?>
So what's wrong with it? It's the while line that is causing the error but I can't see a thing wrong with it, can you? I have also tried using the do while loop but it prints the same error for the while bit on that too.
Yes my database connections are correct
Thanks in advance,
Adam.
Mark Hensler posted this at 17:04 — 14th December 2001.
He has: 4,048 posts
Joined: Aug 2000
What is the error?
Is $news a valid mySQL result?
a_gajic posted this at 21:05 — 14th December 2001.
They have: 71 posts
Joined: Aug 2001
Yes news is valid.
Warning: Supplied argument is not a valid MySQL result resource in C:\apache\server\htdocs/agNews/read.php on line 8
that is the error
here is the line above the while command..
<?php
$news = mysql_query(\"SELECT * FROM news ORDER BY date DESC LIMIT 8;\") || die(\"Cannot select records\");
?>
Is it my query? It's the only other thing that I can think of..
Mark Hensler posted this at 05:36 — 15th December 2001.
He has: 4,048 posts
Joined: Aug 2000
No, that error tells you that $news is not valid.
This should give you more debuging help:
<?php
$query = \"SELECT * FROM news ORDER BY date DESC LIMIT 8\";
$result = mysql_query($query);
if (!$result) {
echo \"\n\n\";
echo \"<!--\n\";
echo \"FILE: \" . __FILE__ . \"\n\";
echo \"LINE: \" . __LINE__ . \"\n\";
echo \"\n\";
echo \"QUERY ERROR:\n\";
echo mysql_error() . \"\n\";
echo \"\n\";
echo \"QUERY:\n\";
echo $query . \"\n\";
echo \"-->\n\";
echo \"\n\";
}
while ($result && $row=mysql_fetch_array($result)) {
// do something
}
?>
Mark Hensler
If there is no answer on Google, then there is no question.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.