Simsonite Posted November 29, 2008 Share Posted November 29, 2008 Hi, Firstly i bet this error is so obvious, but i just cant see it. Here is the error message Parse error: syntax error, unexpected T_STRING in /home/dancdoit/public_html/news/test.php on line 9 Here is the code <?php include 'includes/config.php'; include 'includes/dbopen.php'; $query = "SELECT * FROM tt_posts"; $result = mysql_query($query) or die('Error : ' . mysql_error()); $content = "<ol>"; while($row = mysql_fetch_array($result, MYSQL_NUM)) { $content = "<div id=\"news <?php echo $row['id'] ?>\">"; $content .= "<div id=\"newsheader\"><h2><?php echo $row['title'] ?></h2></div>"; $content .= "<div id=\"newscontent\"><p><?php echo $row['body'] ?></p>"; $content .= "<hr>"; $content .= "<p align=\"right\"><?php echo \"<a href='comment \" . $row['id'] . \".php'>Comments</a>\"; ?></p>"; $content .= "<div id=\"newsfooter\">"; $content .= "<p id=\"author\"><a href=\"/forums/memberlist.php?mode=viewprofile&u=<?php echo $row['uid'] ?>\"><?php echo $row['author'] ?></a></p>"; $content .= "<p id=\"date\"><?php echo $row['created'] ?></p>"; $content .= "</div>"; $content .= "</div>"; $content .= "<br />"; $content .= "<br />"; } $content .= "</ol>"; include 'includes/dbclose.php'; ?> Quote Link to comment Share on other sites More sharing options...
trq Posted November 29, 2008 Share Posted November 29, 2008 Your already within <?php ?> tags, so you can remove that form all your lines. $content = "<div id=\"news {$row['id']}\">"; Quote Link to comment Share on other sites More sharing options...
Simsonite Posted November 30, 2008 Author Share Posted November 30, 2008 Lol thanks i told you it was something really stupid. Quote Link to comment Share on other sites More sharing options...
Simsonite Posted November 30, 2008 Author Share Posted November 30, 2008 Hmm that gets rid of the errors but now it isnt echoing anything? Quote Link to comment Share on other sites More sharing options...
DSGameMaker Posted November 30, 2008 Share Posted November 30, 2008 Post your modified code Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted November 30, 2008 Share Posted November 30, 2008 All your output is stored in your $content variable. You'll need to use echo $content; In order for anything to output. Quote Link to comment Share on other sites More sharing options...
Simsonite Posted November 30, 2008 Author Share Posted November 30, 2008 here is the new code <?php include 'includes/config.php'; include 'includes/dbopen.php'; $query = "SELECT * FROM tt_posts"; $result = mysql_query($query) or die('Error : ' . mysql_error()); while($row = mysql_fetch_array($result, MYSQL_NUM)) { $content = "<ol>"; $content = "<div id=\"news {$row['id']}\">"; $content .= "<div id=\"newsheader\"><h2>{$row['title']}</h2></div>"; $content .= "<div id=\"newscontent\"><p>{$row['body']}</p>"; $content .= "<hr>"; $content .= "<p align=\"right\"><a href='comment/{$row['id']}.php'>Comments</a></p>"; $content .= "<div id=\"newsfooter\">"; $content .= "<p id=\"author\"><a href=\"/forums/memberlist.php?mode=viewprofile&u={$row['uid']}\">{$row['author']}</a></p>"; $content .= "<p id=\"date\">{$row['created']}</p>"; $content .= "</div>"; $content .= "</div>"; $content .= "<br />"; $content .= "<br />"; $content .= "</ol>"; } echo $content; include 'includes/dbclose.php'; ?> Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted November 30, 2008 Share Posted November 30, 2008 And it still not outputting anything? Looking at your code, this: while($row = mysql_fetch_array($result, MYSQL_NUM)) { $content = "<ol>"; $content = "<div id=\"news {$row['id']}\">"; $content .= "<div id=\"newsheader\"><h2>{$row['title']}</h2></div>"; $content .= "<div id=\"newscontent\"><p>{$row['body']}</p>"; needs to be $content = null; while($row = mysql_fetch_assoc($result)) { $content .= "<ol>"; $content .= "<div id=\"news {$row['id']}\">"; $content .= "<div id=\"newsheader\"><h2>{$row['title']}</h2></div>"; $content .= "<div id=\"newscontent\"><p>{$row['body']}</p>"; Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted November 30, 2008 Share Posted November 30, 2008 It won't print anything if there are no rows. Try adding error_reporting(E_ALL); to the top of the code and see if there are any errors. Quote Link to comment Share on other sites More sharing options...
Simsonite Posted November 30, 2008 Author Share Posted November 30, 2008 It is coming up with the following error messages when i do error_reporting(E_ALL); Notice: Undefined index: id in /home/dancdoit/public_html/news/test.php on line 17 Notice: Undefined index: title in /home/dancdoit/public_html/news/test.php on line 18 Notice: Undefined index: body in /home/dancdoit/public_html/news/test.php on line 19 Notice: Undefined index: id in /home/dancdoit/public_html/news/test.php on line 21 Notice: Undefined index: uid in /home/dancdoit/public_html/news/test.php on line 23 Notice: Undefined index: author in /home/dancdoit/public_html/news/test.php on line 23 Notice: Undefined index: created in /home/dancdoit/public_html/news/test.php on line 24 I have copied the script to connect to the database into the script but it still doesnt work. The same script works for other pages Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted November 30, 2008 Share Posted November 30, 2008 You have got the names of the rows wrong then. Check the row names in your database Quote Link to comment Share on other sites More sharing options...
Simsonite Posted November 30, 2008 Author Share Posted November 30, 2008 Nope they were right i think something went wrong when i was connecting to the database because i inserted a different script to connect to the database and it worked What is wrong with this script? <?php $database[dbserver]="localhost"; $database[dbuser]="*******"; $database[dbname]="*******"; $database[dbpass]="****"; $connect = mysql_connect($database['dbserver'], $database['dbuser'], $database['dbpass']); $select= mysql_select_db($database['dbname']); $query = "SELECT * FROM tt_posts"; $result = mysql_query($query) or die('Error : ' . mysql_error()); while($row = mysql_fetch_array($result, MYSQL_NUM)) { ?> Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted November 30, 2008 Share Posted November 30, 2008 Your array key names. $database[dbpass] = "*****"; should be $database['dbpass'] = "*****"; You need to use quotes for everything except numbers or vars or defined words. Quote Link to comment Share on other sites More sharing options...
Simsonite Posted November 30, 2008 Author Share Posted November 30, 2008 Thanks so much for your help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.