gwolff2005 Posted November 21, 2009 Share Posted November 21, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/182424-php-mysql-query-blog-latest-results/ Share on other sites More sharing options...
waynew Posted November 21, 2009 Share Posted November 21, 2009 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']; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/182424-php-mysql-query-blog-latest-results/#findComment-962697 Share on other sites More sharing options...
gwolff2005 Posted November 21, 2009 Author Share Posted November 21, 2009 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!!! Quote Link to comment https://forums.phpfreaks.com/topic/182424-php-mysql-query-blog-latest-results/#findComment-962707 Share on other sites More sharing options...
waynew Posted November 21, 2009 Share Posted November 21, 2009 I'm guessing that Wordpress already takes notice of the current datetime. What are you trying to do with Wordpress that is causing you problems? Quote Link to comment https://forums.phpfreaks.com/topic/182424-php-mysql-query-blog-latest-results/#findComment-962713 Share on other sites More sharing options...
gwolff2005 Posted November 21, 2009 Author Share Posted November 21, 2009 wordpress does not cause me any trouble (so far) But I have no clue how I can put on my main site (different domain) the code that it shows always the latest blogpost with a certain number of words. Quote Link to comment https://forums.phpfreaks.com/topic/182424-php-mysql-query-blog-latest-results/#findComment-962720 Share on other sites More sharing options...
waynew Posted November 21, 2009 Share Posted November 21, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/182424-php-mysql-query-blog-latest-results/#findComment-962722 Share on other sites More sharing options...
gwolff2005 Posted November 21, 2009 Author Share Posted November 21, 2009 Both are on the same server. What do you mean with the schema/structure of wordpress blog table. I know Thsat for example with feedburner you can have the same. It creates a javascript code with your latest blogentry. I just don't want to be dependend on another party. Quote Link to comment https://forums.phpfreaks.com/topic/182424-php-mysql-query-blog-latest-results/#findComment-962734 Share on other sites More sharing options...
waynew Posted November 21, 2009 Share Posted November 21, 2009 What is the Wordpress table that contains these blog posts and what kind of columns does this table have? Quote Link to comment https://forums.phpfreaks.com/topic/182424-php-mysql-query-blog-latest-results/#findComment-962736 Share on other sites More sharing options...
gwolff2005 Posted November 21, 2009 Author Share Posted November 21, 2009 The database is called guntmar. the table is called wp_posts there are columns which are called post_date, post_date_gmt, post_content, post_title Quote Link to comment https://forums.phpfreaks.com/topic/182424-php-mysql-query-blog-latest-results/#findComment-962758 Share on other sites More sharing options...
waynew Posted November 21, 2009 Share Posted November 21, 2009 And what kind of columns are these? Text, varchar, datetime? Quote Link to comment https://forums.phpfreaks.com/topic/182424-php-mysql-query-blog-latest-results/#findComment-962763 Share on other sites More sharing options...
gwolff2005 Posted November 21, 2009 Author Share Posted November 21, 2009 post_date datetime post_date_gmt datetime post_content longtext post_title text Quote Link to comment https://forums.phpfreaks.com/topic/182424-php-mysql-query-blog-latest-results/#findComment-962766 Share on other sites More sharing options...
jamesxg1 Posted November 21, 2009 Share Posted November 21, 2009 http://php.net/manual/en/function.mysql-affected-rows.php Quote Link to comment https://forums.phpfreaks.com/topic/182424-php-mysql-query-blog-latest-results/#findComment-962804 Share on other sites More sharing options...
waynew Posted November 22, 2009 Share Posted November 22, 2009 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/182424-php-mysql-query-blog-latest-results/#findComment-963147 Share on other sites More sharing options...
gwolff2005 Posted November 22, 2009 Author Share Posted November 22, 2009 Wow aynewex. You are my hero. I will straight try that out. Thanks so much. You are a life saver!!! Quote Link to comment https://forums.phpfreaks.com/topic/182424-php-mysql-query-blog-latest-results/#findComment-963151 Share on other sites More sharing options...
gwolff2005 Posted November 22, 2009 Author Share Posted November 22, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/182424-php-mysql-query-blog-latest-results/#findComment-963213 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.