Jump to content

Page won't ouput any thing after this PHP, but runs PHP code with no errors


zxnet2k

Recommended Posts

Heya Guys,

 

New to the forum and have been battling for this problem for quite a while with no luck, thought I would call in expert help :)

 

Basically I have the following PHP code that runs from a require statement on a different page, and it is designed to pull the last 10 posts from the DB table and display title, date short extract etc.

 

<?php

$sql = "select id, title, content, date from posts where active = '1' order by date DESC";
		$result = mysql_query($sql,$conn) or die(mysql_error());
		$num_rows = mysql_num_rows($result);

		if ($num_rows != 0)
		{

	         $n = 0;
		while($row = mysql_fetch_array($result) or die(mysql_error())){
                                 $title = $row['title'];
                                  echo $title;
			if ($n < 10) {
				echo "<div class=\"topTenRow\">";
				$id = $row['id'];
				$date=date("d/m/Y", strtotime($row["date"]));
				$title = $row['title'];
				$content  = $row['content'];
				$text = $content;
				$text = substr($text,0,120);
				$text = substr($text,0,strrpos($text,' '));
				$text = $text."...";
				echo "<div class=\"TTdate\">$date</div>";
				echo "<strong>" . $title . "</strong>";
				echo "<a class=\"topTenLink\" href=\"posts.php?id=$id\"><img alt=\"Read More\" src=\"images/buttons/btnReadMore.png\"/></a>";

				echo "$text </div>";
				$n = $n + 1;
				}

			}
		}



?>

 

The strange thing is that the code executes on the page and the require statement show the expected result, however all the rest of the code on the initial page after the require doesn't show anything, and even the source code stops there as well (when viewing it in a browser)

 

Any ideas if there is something in the code above which is causing it, or could it be a problem elsewhere - anyone ever had this issue before?

 

I would appreciate all recommendations and suggestions, even if they don't relate directly to the problem above :)

Link to comment
Share on other sites

Hi guys, just as I post it I figure it out - typical! For anyone wondering there was a jquery conflict issue with another part of the page.

 

Seeing as how the post is still up, can anyone comment on the code I have used above?  Is this an effective way of pulling a top ten most recent posts box or could it be done differently?

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.