0

Hello,
i am new to php and from this project i have started my php learning so first of sorry if my question is simple to ask but its difficult for me to understand the error and i want to learn php so i really need from all php expert available here.

so i am getting error in generating news or latest post.. here is my code

<?
include("includes/connect.php");
$select_posts = "select * from posts order by rand() LIMIT 0,2";
$run_posts = mysql_query($select_post);

while($row=mysql_fetch_array($run_post)){

$title = $row ['post_title'];
$date = $row ['post_date'];
$author = $row ['post_author'];
$image = $row ['post_image'];
$content = substr($row ['post_content'],0,200);+
}
?>

<h2><?php echo $title; ?></h2>

Following i am getting in my news page :

Notice: Undefined variable: title in G:\wamp\www\rect\includes\news_data.php on line 16

2
Contributors
1
Reply
10
Views
2 Years
Discussion Span
Last Post by albucurus
0

Try this:

<? php
  include("includes/connect.php");
  $select_posts = "select * from posts order by rand() LIMIT 0,2";
  $run_posts = mysql_query($select_post);
  while($row=mysql_fetch_array($run_post)){
      $title = $row ['post_title'];
      $date = $row ['post_date'];
      $author = $row ['post_author'];
      $image = $row ['post_image'];
      $content = substr($row ['post_content'],0,200);
  }
  echo "<h2>".$title."</h2>";
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.