Jump to content

News in index.php


Joshv1288

Recommended Posts

Without more info I'm just going to give you a very generic example. Work it out from here.

 

<?php

  // connect to db

  $sql "SELECT title,article,stamp FROM news ORDER BY stamp";

  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      while ($row = mysql_fetch_assoc($result)) {
        echo "<h1>{$row['stamp']} - {$row['title']}</h1>";
        echo "<p>{$row['article']}</p>";
      }
    }
  }

?>

Link to comment
https://forums.phpfreaks.com/topic/115948-news-in-indexphp/#findComment-596180
Share on other sites

heres my db where my news is stored

 
      CREATE TABLE news_posts (
      id INT(11) NOT NULL AUTO_INCREMENT,
      title VARCHAR(70) NOT NULL,
      author VARCHAR(50) NOT NULL,
      post TEXT NOT NULL,
      DATE DATETIME NOT NULL,
      PRIMARY KEY (id)
      );

and go here to see how my index is setup http://h3swatlg.exofire.net/index.php

Link to comment
https://forums.phpfreaks.com/topic/115948-news-in-indexphp/#findComment-596183
Share on other sites

ok i added the code directly where my news should go and edited a little and i get this error

 

Parse error: syntax error, unexpected '>' in /home/h3swat/public_html/news/index.php on line 115

 

 

105- echo "            <td valign=\"top\" class=\"windowbg\">;
<?php

  include('mysql_connect.php');

110-  $sql 'SELECT title,post,id FROM news_posts ORDER BY id';

  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      while ($row = mysql_fetch_assoc($result)) {
    115-    echo "<h1>{$row['id']} - {$row['title']}</h1>";
        echo "<p>{$row['post']}</p>";
      }
    }
  }

?>
122-echo "</td>\n"; 

Link to comment
https://forums.phpfreaks.com/topic/115948-news-in-indexphp/#findComment-596590
Share on other sites

 


<?php
include 'conf.php'; //configuration file
include 'opendb.php'; //contains the open database commands

$sql = "SELECT * FROM news_posts";
$res = mysql_query($sql) or die (mysql_error());

while($row = mysql_fetch_array($res,MYSQL_ASSOC)){
       
       $data = sprintf("<h1> %s </h1> <p> %s </p> <p> Written by: %s</p>",
       $row['title'],$row['post'],$row['author']);
       echo $data;


}
?>

Link to comment
https://forums.phpfreaks.com/topic/115948-news-in-indexphp/#findComment-596602
Share on other sites

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/h3swat/public_html/news/index.php on line 109

 

<?php
include 'mysql_connect.php'; //contains the open database commands

109-$sql = "SELECT * FROM news_posts";
$res = mysql_query($sql) or die (mysql_error());

while($row = mysql_fetch_array($res,MYSQL_ASSOC)){
       
       $data = sprintf("<h1> %s </h1> <p> %s </p> <p> Written by: %s</p>",
       $row['title'],$row['post'],$row['author']);
       echo $data;


}
?>

Link to comment
https://forums.phpfreaks.com/topic/115948-news-in-indexphp/#findComment-597114
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.