hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : PHP/mysql issue
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

PHP/mysql issue

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 12-03-2006, 12:03 AM
40sixty 40sixty is offline
Chilling in Pen Island
 
Join Date: May 2006
Posts: 872

PHP/mysql issue


I have a small issue with PHP/mysql.

I'm trying to get the TITLES of the last 5 posts I made in my blog orderd by the date.

PHP Code:
<?
mysql_connect
("server""user""pass") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());

  
$query mysql_query("SELECT * FROM wp_posts ORDER BY date DESC LIMIT 5");
  while(
$row mysql_fetch_array($query))
    {
     
$default_title $row['title'];
     
$default_date $row['date'];
  
$default_title stripslashes($default_title);
   }
 echo 
$default_title;

?>
Now for some odd reason, It shows only one title.
and that title has the ID 5.
So, I was thinking then I changed LIMIT 5 to LIMIT 2 and that one title that was displayed changed to the title from blog entry 2 (which is ID 2).

Database is like.

ID TITLE DATE CONTENT

__________________
hosted by HawkHost
I Recommend: LimeStone Networks!
The OverSeller Defender!

Reply With Quote


Sponsored Links
  #2  
Old 12-03-2006, 12:23 AM
orbitz orbitz is offline
Web Hosting Master
 
Join Date: Mar 2004
Posts: 1,301
you need to have the echo part inside the while loop. Right now, it is outside of the loop; thus only the last title gets echoed out.

Reply With Quote
  #3  
Old 12-03-2006, 12:26 AM
40sixty 40sixty is offline
Chilling in Pen Island
 
Join Date: May 2006
Posts: 872
Ah! Simple mistake!
Thanks for telling me man, fixed the problem!

__________________
hosted by HawkHost
I Recommend: LimeStone Networks!
The OverSeller Defender!

Reply With Quote
Sponsored Links
Reply

Related posts from TheWhir.com
Title Type Date Posted
PayPal UK IPN Issues Impact Web Hosts, Users Web Hosting News 2013-02-01 09:34:43
Web Host Rackspace Launches Private Beta for MySQL Cloud Database Web Hosting News 2011-12-01 21:09:51
Parallels Now Offering Licenses for CloudLinux OS Web Hosting News 2011-10-26 17:29:25
Web Hosting Software Firm CloudLinux Releases CloudLinux OS Version 6.1 Web Hosting News 2011-09-13 14:08:49
Web Host FireHost Partners with Cloud Security Firm Gazzang for Data Encryption Web Hosting News 2011-08-16 20:33:43


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?