Jump to content

PhP Mysql query blog latest results


gwolff2005

Recommended Posts

Hi guys,

I need your help. I have a blog and on a complete different page my homepage. Now what I want to do is that if I post a new post on my blog that the first 35 words  of it appear in a layer, and then as well next to it the publish date.

I realized that I would need to create an mysql query which comes up with the last entry,

How can I do that? And then which is probably more complicated how can I tell mysql to give me just 35 words, or can I limit in any way the layer????

I am helpless! I would deeply appreciate if someone could help me!

Thanks!

Link to comment
Share on other sites

You'll need a datetime column in your blog post table.

 

date_posted DATETIME NOT NULL

 

When inserting a new blog post into your database table, you'll need to give the datetime, which is:

 

$date_posted = date("Y-m-d H:i:s");

 

When selecting from your blog post table, you'll need to order it like so:

 

$result = mysql_query("SELECT * FROM blog ORDER BY date_posted DESC") or trigger_error(mysql_error());

 

If you're only wanting to show the first 35 characters of something, do this (assuming the main text of the blog post is in a column called "body")

 

<?php
while($row = mysql_fetch_assoc($result)){
       
        if(strlen(trim($row['body'])) > 35){
               echo substr($row['body'],0,35).' [...]';
        }       
        else{
               echo $row['body'];
        }
}
?>

Link to comment
Share on other sites

WOW waynewex you are amazing. Thanks for the help. What I still dont understand how can I insert the datetime when posting. I use wordpress. Is there any chance you could help me with that while we chat on skype with each other, so I can tell you where I have the probs. Thanks so much!!!

Link to comment
Share on other sites

Well, firstly you'll have to make sure that said domain is on the server as your Wordpress database. Otherwise, you'll have to make sure that the database on your other server allows external connections. Have you looked into the schema/structure of the Wordpress blog table?

Link to comment
Share on other sites

post_date  datetime

post_date_gmt datetime

post_content longtext

post_title text

 

Then

 

<?php
$limit = 6;
$query = "SELECT * FROM wp_posts ORDER BY post_date DESC LIMIT $limit";
$result = mysql_query($query) or trigger_error(mysql_error());

while($row = mysql_fetch_assoc($result)){
        //etc
}
?>

Link to comment
Share on other sites

Hey waynewex,

I will try now your code...

due to the fact that I am rally desperate. I tried the following with a applet form feedburner.

Hi guys I need your help,

 

I have a javascript snippet which I include in my webpage. What should be shown in Verdana/11.

What do I do wrong? Please help me!! Thanks!!

 

 

<html>
<head>
<style type="text/css">
p
{
font-family:"Verdana";
font-size:11px;
}
</style>
</head>

<body>
<p><script src="http://feeds.feedburner.com/GuntmarsBlog?format=sigpro" type="text/javascript" ></script></p><noscript><p>Subscribe to RSS headline updates from: <a href="http://feeds.feedburner.com/GuntmarsBlog"></a><br/>Powered by FeedBurner</p> </noscript>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.