Page 1 of 1
Display recent added post.
Posted: Wed Oct 05, 2011 2:36 am
by jauson
Hi guys!
Need your help badly!
say there are 25 inserted index_id in my t_board, and I want to display the last index_id w/c index_id 25 in my view_form.
heres my code; view_form.php
==========================
$sql = "SELECT * from t_board LIMIT 0,1"; <---- what should I do or add to make my script decrement.
note: I only limit my form to display only 1.
==========================
Any help will be appreciated!

Re: Display recent added post.
Posted: Wed Oct 05, 2011 8:43 am
by Celauran
Code: Select all
SELECT col1, col2, col3
FROM tablename
WHERE whatever
ORDER BY id DESC
LIMIT 1
Might be faster to split it into two queries, though; one to get MAX(id) then another using that id in a WHERE clause. This might also be better suited to the SQL forum.
Re: Display recent added post.
Posted: Wed Oct 05, 2011 9:41 am
by jauson
heres my script $sql = "SELECT * from t_board index DESC LIMIT 1";
|
|
Notice: Undefined index: index in C:\xampp\htdocs\Lacson_exam\src\view.php on line 11.

thank you!

Re: Display recent added post.
Posted: Wed Oct 05, 2011 9:44 am
by Celauran
What is 'index DESC'?
Re: Display recent added post.
Posted: Wed Oct 05, 2011 9:57 am
by jauson
heres my latest error now..
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Lacson_exam\src\view.php on line 26
script is working now but my next problem is my <? if($rows = mysql_fetch_array($result)) ?> etc...
Re: Display recent added post.
Posted: Wed Oct 05, 2011 10:05 am
by Celauran
We can't guess what your code is. It's going to be very difficult to help you without seeing it.
Code: Select all
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Lacson_exam\src\view.php on line 26
most likely means your query returned FALSE, meaning there's an error in the query.
Re: Display recent added post.
Posted: Wed Oct 05, 2011 10:23 am
by jauson
query not running well
$sql = "SELECT ( writer, subject, message, filename ) FROM t_board WHERE ORDER BY index DECS LIMIT 1";
$result = mysql_query($sql);
if (!$result){
echo "could not run query";
exit;
}
tell me is it correct?
Re: Display recent added post.
Posted: Wed Oct 05, 2011 10:29 am
by Celauran
That query is definitely wrong. You haven't specified any criteria for WHERE; you'll either need WHERE field = value, or you'll need to remove the WHERE clause. 'ORDER BY index' is also likely wrong. Do you have a field called index? If so, since it's a reserved word, you'll need to enclose it in backticks (`). If not, you'll need to use a proper field name. DECS should be DESC.
Re: Display recent added post.
Posted: Wed Oct 05, 2011 6:59 pm
by jauson
[SOLVED]
$sql = "SELECT * FROM `t_board` ORDER BY `index` DESC LIMIT 1"; thanks
