how to query sql.....yet again.....(i hate being a noob to s
Moderator: General Moderators
- dull1554
- Forum Regular
- Posts: 680
- Joined: Sat Nov 22, 2003 11:26 am
- Location: 42:21:35.359N, 76:02:20.688W
how to query sql.....yet again.....(i hate being a noob to s
i posted eariler asking about aut_increment, now i want to read from the database and pull out five entrys with the highest post_id number, i don't evem know where to start, could someone help me
any help you guys could give me would be awesome......thanks
any help you guys could give me would be awesome......thanks
Code: Select all
select * from news order by post_id desc limit 5-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
Code: Select all
$query = mysql_query($sql);
$var = mysql_result($query);
echo $var;- dull1554
- Forum Regular
- Posts: 680
- Joined: Sat Nov 22, 2003 11:26 am
- Location: 42:21:35.359N, 76:02:20.688W
when i do that i get this error.....
heres my code
Code: Select all
Warning: Wrong parameter count for mysql_result() in c:\program files\apache group\apache\htdocs\test\news\news.php on line 5Code: Select all
<?php
include "db.php";
$sql = "select * from news order by post_id desc limit 5";
$query = mysql_query($sql);
$var = mysql_result($query);
echo $var;
?>you only need to pull out 1 line, use it like this.
Code: Select all
<?php
$news = mysql_fetch_array(mysql_query("selecy ID from news order by ID DESC limit 1"));
echo $news['ID];
?>- dull1554
- Forum Regular
- Posts: 680
- Joined: Sat Nov 22, 2003 11:26 am
- Location: 42:21:35.359N, 76:02:20.688W
so if i just pull out one line, but make it loop five times and stick the post_text, subject, and date into a array, then print the array......but i guess that won't work will it because if i make it loop five times its gonna pull out the same line, the last line all five times......it would be good if i could pull out the three fields that i need and slap them into a array, heres how my database is setup
DATABASE : news
TABLE :news
FIELDS :post_id | subject | date | post_text
(post_id auto_increments)
i need to pull out subject, date, and post_text, then i want to place those values in a table like this
but i dont have the slightest clue as to how to pull the values from the database.....i hope somone can help my poor poor soul....
DATABASE : news
TABLE :news
FIELDS :post_id | subject | date | post_text
(post_id auto_increments)
i need to pull out subject, date, and post_text, then i want to place those values in a table like this
Code: Select all
<?php
echo "<table>
<tr><td>".$subject." -- ".$date."</td></tr>
<tr><td>".$post_text."</td></tr>
</table>";Code: Select all
<?php
$array = mysql_get_array(mysql_query("`post_id`, `subject`,`date`,`post_text` order by `post_id` limit 1");
echo "<table>
<tr><td>".$array['subject']." -- ".$array['date']."</td></tr>
<tr><td>".$array['post_text']."</td></tr>
</table>";
?>- dull1554
- Forum Regular
- Posts: 680
- Joined: Sat Nov 22, 2003 11:26 am
- Location: 42:21:35.359N, 76:02:20.688W
thanks for the help, i understand that, and honnestly most of the time thats what i do, but there are certain cirsumstances that i need to complete a project in a hasty manner, and i do try to do it myself but you prolly know me by now, i tend to run into many errors, or i hit a stumbling block, and have to start yelling "Help.....I've fallen and i can't get up", but i do understand that me asking on this forum is not always the best way in which to learn, and i really appreciate the immense help qads
- dull1554
- Forum Regular
- Posts: 680
- Joined: Sat Nov 22, 2003 11:26 am
- Location: 42:21:35.359N, 76:02:20.688W
ok i've slaped together a bit of each of your guyses code and this is what i have
when i try to execute this code i get this error;
Code: Select all
<?php
include "db.php";
$query = mysql_query("SELECT * FROM news order by post_id DESC limit 1")
$array = mysql_fetch_array($query);
echo "<table>
<tr><td>".$array['subject']." -- ".$array['date']."</td></tr>
<tr><td>".$array['post_text']."</td></tr>
</table>";
?>Code: Select all
Parse error: parse error, unexpected T_VARIABLE in c:\program files\apache group\apache\htdocs\test\news\news.php on line 4Code: Select all
<?php
$query = mysql_query("SELECT * FROM news order by post_id DESC limit 1")
?>-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA