Welcome to Dream.In.Code
Become a PHP Expert!

Join 136,933 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,858 people online right now. Registration is fast and FREE... Join Now!




Displaying a read more

 
Reply to this topicStart new topic

Displaying a read more

morcomm
28 Mar, 2008 - 05:13 AM
Post #1

New D.I.C Head
*

Joined: 27 Mar, 2008
Posts: 49


My Contributions
Hi, I am totally new to PHP and have managed to create a record insertion form and displaying the data using repeating regions.
The application is needed for creating press releases on our company website.

I have a shorttext section and a longtext row in the database table. The shorttext is to be displayed on a page that acts as a news index, and the longtext is to be displayed in its own page when a "read more" is clicked. Below is my code:

CODE
<?php do { ?>
      <p class="newsHeadlineIndex"> <?php echo $row_Recordset1['headline']; ?> (<?php echo $row_Recordset1['publisher']; ?> - <?php echo $row_Recordset1['pubdate']; ?>)</p>
      <p> <?php echo $row_Recordset1['shorttext']; ?></p>
      <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>


I am thinking that the best way to do this is to print (update) the content to the current page when the "read more" is clicked, but I have no idea how to do this.

PLEASE HELP as I am on a deadline.
User is offlineProfile CardPM
+Quote Post

_net
RE: Displaying A Read More
28 Mar, 2008 - 09:42 AM
Post #2

D.I.C Head
**

Joined: 22 Sep, 2007
Posts: 146


My Contributions
EDIT: Welcome to </DiC> smile.gif Feel free to drop by introduction to introduce yourself to the community.

Your idea of the loop is not bad but I dont recommend a Do While for the procedure you are following.

Do While is an Exit-condition loop as in it does the conditional test at the end of each cycle.. This means the do while will run at least once Even if the loop condition returns to false.

So for example, your variables :
php

<?php
echo $row_Recordset1['headline'];
$row_Recordset1['publisher'];
$row_Recordset1['pubdate'];
?>


will be called before they are assigned a value, therefore printing an error displaying unknown variable.

Use a while loop;

php

<?php
while ($row_Recordset1 = mysql_fetch_assoc($Recordset1))
{
<p class="newsHeadlineIndex"> <?php echo $row_Recordset1['headline']; ?> (<?php echo $row_Recordset1['publisher']; ?> - <?php echo $row_Recordset1['pubdate']; ?>)</p>
<p> <?php echo $row_Recordset1['shorttext']; ?></p>
<?php
}
?>


While loop is an entry-condition loop; it does the conditional tests before launching the loop inside and this is good because it sets the values for the $row_Recordset1 variable at the condition-test part of the loop. smile.gif

I hope i helped a little.

This post has been edited by _net: 28 Mar, 2008 - 09:43 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 10:42PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month