Jump to content

Coding to display data from MySQL


TomFromKWD

Recommended Posts

Morning all,

and Evening everyone else.

 

Im using the following Query to display information from a table

 

<?
include "config.php";
$query1="Select *,DATE_FORMAT(date_posted,'%W,%d %b %Y') as thedate FROM article WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) ORDER BY date_posted DESC LIMIT 1 ";
$blogarticles = mysql_query($query1) or die(mysql_error());
$num = mysql_num_rows($blogarticles);
?>

 

What I am wanting to find out, is as the blog post itself could be pages long at times, is the anyway that further down the page where I actually call the data up onto the page itself I can limit how much of it is displayed?

Ive succesfully added a limit to how many records are shown with the "DES LIMIT 1", is there something I can add to my query, or further down in my displaying table (which I will code just below here) to limit the lines/characters on display until the full article is opened?

 

Display table:

     <table width="75%" border="0" cellspacing="1" align="left">
  <tr>
          <td> </td>
        </tr>
  <tr>
          <td> </td>
        </tr>
  <? 
if($num > 0){
while($row_articles = mysql_fetch_assoc($blogarticles)){
?>
       
           <tr class="title">
          <td><?=$row_articles['title'];?> </td>
        </tr> 
        <tr>
          <td> </td>
        </tr>
        <tr class="tbody">
          <td><?=$row_articles['comments'];?></td>
        </tr>
        <tr>
          <td> </td>
        </tr>

        <tr class="links">
          <td>Date posted: <?=$row_articles['date_posted'];?> | <a href="comments.php?aid=<?=$row_articles['artid'];?>&cid=<?=$row_articles['categoryID'];?>">Comments(<? //echo $row_articles['artid'];		  

	//$thenum=row_articles['artid'];
	$getcomments = "SELECT * FROM article WHERE artchild='".$row_articles['artid']."'";
	if(!$theResult=mysql_query($getcomments)){
	echo mysql_error();
	}else{
	$num_comments=mysql_num_rows($theResult);
	echo $num_comments;
	}
	?>) </a></td>
        </tr>
        <tr class="links">
          <td> </td>
        </tr>
        <tr class="links">
          <td> </td>
        </tr>
	<?
	}
	}else{
	 ?>
	<tr><td><p>There are no articles available at present</p></td></tr>
	<?
	}
	?>
	<tr>		</tr>
      </table>

 

 

 

Just to clarify 'comments' is the table field that holds the blog data, it also holds comments on the blog, but the child ID is what differentiates them from one another.

 

 

 

Thanks in advance for your help ladies & gents

 

 

Tom

Link to comment
Share on other sites

You could make a substr($row_articles['comments'], 0, 300) so that your post only shows 300 characters; don't forget to add ellipsis (...) at the end of it.

 

That worked beautifully Silkfire, thanks a bunch!

 

What I ended up using is

 

<?=substr($row_articles['comments'], 0, 300);?>.... <a href="comments.php?aid=<?=$row_articles['artid'];?>&cid=<?=$row_articles['categoryID'];?>">Read More</a>

 

that seems to be working well!

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.