Joshv1288 Posted July 22, 2008 Share Posted July 22, 2008 i was wondering how to add my news system into my index Link to comment https://forums.phpfreaks.com/topic/115948-news-in-indexphp/ Share on other sites More sharing options...
trq Posted July 22, 2008 Share Posted July 22, 2008 A little more detail please? Link to comment https://forums.phpfreaks.com/topic/115948-news-in-indexphp/#findComment-596144 Share on other sites More sharing options...
Joshv1288 Posted July 22, 2008 Author Share Posted July 22, 2008 how do i make my index display my news like right now i have to manually go in to the index to add news but now i have a system and want to add it into my index how would i go about doin that Link to comment https://forums.phpfreaks.com/topic/115948-news-in-indexphp/#findComment-596151 Share on other sites More sharing options...
trq Posted July 22, 2008 Share Posted July 22, 2008 Still more details are required. Where is your news stored, a db? Do you know anything about selecting data from a database? Link to comment https://forums.phpfreaks.com/topic/115948-news-in-indexphp/#findComment-596157 Share on other sites More sharing options...
Joshv1288 Posted July 22, 2008 Author Share Posted July 22, 2008 yea my news is stored in a db and idk how to get data from a db Link to comment https://forums.phpfreaks.com/topic/115948-news-in-indexphp/#findComment-596175 Share on other sites More sharing options...
trq Posted July 22, 2008 Share Posted July 22, 2008 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 More sharing options...
Joshv1288 Posted July 22, 2008 Author Share Posted July 22, 2008 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 More sharing options...
trq Posted July 22, 2008 Share Posted July 22, 2008 I've given you an example, how about you have a go and tell us what the problem is (if any)? Link to comment https://forums.phpfreaks.com/topic/115948-news-in-indexphp/#findComment-596189 Share on other sites More sharing options...
Joshv1288 Posted July 22, 2008 Author Share Posted July 22, 2008 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 More sharing options...
turkman Posted July 22, 2008 Share Posted July 22, 2008 <?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 More sharing options...
waynew Posted July 22, 2008 Share Posted July 22, 2008 facepalm.jpg Link to comment https://forums.phpfreaks.com/topic/115948-news-in-indexphp/#findComment-596610 Share on other sites More sharing options...
Joshv1288 Posted July 23, 2008 Author Share Posted July 23, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.