Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old April 18th, 2003, 11:30 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
Reading the last five entries in database from bottom to top

I have a database called main_news with three fields: Subject, Text and an auto-incrementing field called newsid.

I want to read out the last five news posts from bottom to top, so if i post something it comes out first and the other 4 below it. I want the subject to come out first and in bold, then a <br> and then the text of the news, then a <br> then the next subject etc.

I have been stuck on figuring out how exactly to do this.. any help is appreciated, thanks in advance.

Reply With Quote
  #2  
Old April 18th, 2003, 11:54 PM
sliver's Avatar
sliver sliver is offline
Moderator
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: WI, USA
Posts: 906 sliver User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 21 m 10 sec
Reputation Power: 2
Send a message via AIM to sliver Send a message via XFire to sliver
RE: Reading the last five entries in database from bottom to top

php Code:
Original - php Code
  1. <?php
  2. $conn=mysql_connect("localhost","","");
  3. mysql_select_db("",$conn);
  4. $result=mysql_query("select * from main_news order by newsid desc limit 0,5");
  5. while($result=mysql_fetch_array($do)) {
  6.     print "<b>".$row["subject"]."</b><br>";
  7.     print $row["text"]."<br>";
  8. }
  9. mysql_close($conn);
  10. ?>

Reply With Quote
  #3  
Old April 19th, 2003, 12:45 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Reading the last five entries in database from bottom to top

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/ecliptic/public_html/index.php on line 34

i get that when i use your code
while($result=mysql_fetch_array($do)) {
print "<b>".$row["subject"]."</b><br>";
print $row["text"]."<br>";
}

Reply With Quote
  #4  
Old April 19th, 2003, 12:57 AM
sliver's Avatar
sliver sliver is offline
Moderator
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: WI, USA
Posts: 906 sliver User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 21 m 10 sec
Reputation Power: 2
Send a message via AIM to sliver Send a message via XFire to sliver
RE: Reading the last five entries in database from bottom to top

Oh, right woops messed up my variable names this'll work:
php Code:
Original - php Code
  1. <?php
  2. $conn=mysql_connect("localhost","","");
  3. mysql_select_db("",$conn);
  4. $result=mysql_query("select * from main_news order by newsid desc limit 0,5");
  5. while($result=mysql_fetch_array($result)) {
  6.     print "<b>".$row["subject"]."</b><br>";
  7.     print $row["text"]."<br>";
  8. }
  9. mysql_close($conn);
  10. ?>

Reply With Quote
  #5  
Old April 19th, 2003, 01:06 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Reading the last five entries in database from bottom to top

I changed the $do to $result and im still getting the same error

Reply With Quote
  #6  
Old April 19th, 2003, 11:57 AM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: Reading the last five entries in database from bottom to top

I noticed another error in the code, try this...

<?php
$conn=mysql_connect("localhost","","");
mysql_select_db("",$conn);
$result=mysql_query("select * from main_news order by newsid desc limit 0,5");
while($row=mysql_fetch_array($result)) {
print "<b>".$row["subject"]."</b><br>";
print $row["text"]."<br>";
}
mysql_close($conn);
?>

Changed the variable $result to $row in the while statement. Seems to work for me

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Reading the last five entries in database from bottom to top


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT