Archive blog page
Im haveing a little problem with my archive page for my blog here is the code
<?php
-----conect to database------
-----select database------
$result = mysql_query("SELECT timestamp, id, title FROM php_blog WHERE FROM_UNIXTIME( timestamp, '%Y' ) = $year ORDER BY id DESC");
while ($row = mysql_fetch_array($result))
{$date = date("l F d Y",$row["timestamp"]);
$id = $row["id"];
$title = $row["title"];
echo "$date<br><a href=\"journal.php?id=$id\">$title</a><br><br>";
}
?>
here is the error message
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/vhosts_111mb/eimblog.111mb.com/archive.php on line 19
timjpriebe posted this at 12:37 — 31st May 2005.
He has: 2,667 posts
Joined: Dec 2004
If you test the query outside of the program, does it return any results?
baldrick posted this at 18:06 — 31st May 2005.
He has: 388 posts
Joined: Apr 2005
no
timjpriebe posted this at 18:21 — 31st May 2005.
He has: 2,667 posts
Joined: Dec 2004
Try changing that first line to this one and see if it gives you a more detailed error message:
<?php
$result = mysql_query(\"SELECT timestamp, id, title FROM php_blog WHERE FROM_UNIXTIME( timestamp, '%Y' ) = $year ORDER BY id DESC\") or die(mysql_error());
?>
Tim
http://www.tandswebdesign.com
timjpriebe posted this at 18:23 — 31st May 2005.
He has: 2,667 posts
Joined: Dec 2004
Also, is $year definitely set beforehand? If not, it could cause the problem.
baldrick posted this at 18:24 — 31st May 2005.
He has: 388 posts
Joined: Apr 2005
i got this
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY id DESC' at line 1
timjpriebe posted this at 18:42 — 31st May 2005.
He has: 2,667 posts
Joined: Dec 2004
Yep, that means $year is likely not defined. Try echoing $year right before you assign $result.
baldrick posted this at 18:44 — 31st May 2005.
He has: 388 posts
Joined: Apr 2005
o sorry years is not defined sorry for the bother.
baldrick posted this at 18:59 — 31st May 2005.
He has: 388 posts
Joined: Apr 2005
this is what the year variable should be right
$year= date("Y");
timjpriebe posted this at 19:04 — 31st May 2005.
He has: 2,667 posts
Joined: Dec 2004
Are you looking for the current year (ie 2005)? If so, that looks right to me.
Maybe you should post more of your code.
baldrick posted this at 19:15 — 31st May 2005.
He has: 388 posts
Joined: Apr 2005
yes i am looking for the current year and thanks again for all your help
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.