Page 1 of 1

News Story Preview.. Read more link.

Posted: Tue Aug 05, 2008 4:43 pm
by odie2828
Everah | Please use bbCode tags when posting code in the forums. We have that rule in place for a reason.

I want to only show a preview of the text that is getting pulled from MYSQL, and the have it place a "read more" link. then when you click the link only that story will come uup in a pop up window.

Here is my code:

Code: Select all

<?php
 
 
 
include("config.php");
 
       $result = mysql_query("SELECT * FROM news ORDER BY newsid DESC",$connect);
 
        
        $text = $_POST['text1'];
        $newtext = wordwrap($text, 8, "\n");
        
        while($myrow = mysql_fetch_assoc($result))
 
             {
    $text = $myrow['text1'];
        
               echo "<b>Title: ";
 
               echo $myrow['title'];
 
               echo "</b><br>On: <i>";
 
               echo $myrow['dtime'];
 
               echo "</i><hr align=left width=160>";
 
               echo wordwrap($text, 30, "<br />");
 
               echo "<br><a href=\"read_more.php?newsid=$myrow[newsid]\">Read More...</a>
 
                || <br><hr align=left width=160>";
 
             }
 
?>

Please help......

Re: News Story Preview.. Read more link.

Posted: Tue Aug 05, 2008 4:46 pm
by RobertGonzalez
What is wrong with your code now?

Re: News Story Preview.. Read more link.

Posted: Tue Aug 05, 2008 4:58 pm
by odie2828
ok i am sorry i am new to this.

i figured it out though. thank you.

here is my new code:

Code: Select all

<?php
 
 
 
include("config.php");
 
       $result = mysql_query("SELECT * FROM news ORDER BY newsid DESC",$connect);
 
        
        $text = $_POST['text1'];
        $newtext = wordwrap($text, 8, "\n");
        
        while($myrow = mysql_fetch_assoc($result))
 
             {
        $text = $myrow['text1'];
        $text2 = wordwrap($text, 30, "<br />");
               
 
               echo "<b>Title: ";
 
               echo $myrow['title'];
 
               echo "</b><br>On: <i>";
 
               echo $myrow['dtime'];
 
               echo "</i><hr align=left width=160>";
 
               echo substr($text2, 0, 200);
 
               echo "<br><a href=\"read_more.php?newsid=$myrow[newsid]\">Read More...</a>
 
                || <br><hr align=left width=160>";
 
             }
 
?>

Re: News Story Preview.. Read more link.

Posted: Tue Aug 05, 2008 5:34 pm
by odie2828
How do i limit the number of news storries that it will show when it is fetching the results?

Re: News Story Preview.. Read more link.

Posted: Tue Aug 05, 2008 5:41 pm
by RobertGonzalez
by using a limit clause in your SQL or by setting a loop limit when displaying.

Re: News Story Preview.. Read more link.

Posted: Tue Aug 05, 2008 5:42 pm
by Dynamis
If I am understanding you correctly, you want to limit how many news stories are printed out. So instead of using:

Code: Select all

while($myrow = mysql_fetch_assoc($result))
Use a for loop:

Code: Select all

for($x=0;$myrow = mysql_fetch_assoc($result) && $x < 20; $x++)
Replace 20 with how many stories you want it to show.

Re: News Story Preview.. Read more link.

Posted: Tue Aug 05, 2008 5:55 pm
by odie2828
That didnt work.

it didnt display any data from the SQL.

can i put somthing in this clause:

Code: Select all

 
$result = mysql_query("SELECT * FROM news ORDER BY newsid DESC",$connect);
 

Re: News Story Preview.. Read more link.

Posted: Tue Aug 05, 2008 5:58 pm
by Dynamis
Thats what Everah mentioned. You use the MySQL LIMIT statement. If this doesn't explain enough, just google "MySQL Limit".

Re: News Story Preview.. Read more link.

Posted: Wed Aug 06, 2008 11:53 am
by odie2828
Thank you very much for your help!!

I used the LIMIT code.

Code: Select all

 
$result [color=#0000FF]= mysql_query[/color]("[color=#FF0000]SELECT * FROM news ORDER BY newsid DESC LIMIT 0, 5"[/color],$connect);