jeaker Posted November 9, 2006 Share Posted November 9, 2006 I have been working on this code for 3 days now and i am stumped. It is supposed to go to my server and get the stuff in the table "news" and output the news articles that are in the database. I cannot for the life of me figure out what the problem may be. Any help would be greatly appreciated.[code]<?php$db_name = "newdb";$table_name = "news";$connection = @mysql_connect("db.blah.com", "johndoe", "blah") or die(mysql_error());$db = @mysql_select_db($db_name, $conection) or die(mysql_error());$sql = "SELECT*FROM $table_name ORDER BY id";$result = @mysql_query($sql, $connection) or die(mysql_error());while ($row = mysql_fetch_array($result)) { $id = $row['id']; $title = $row['title']; $content = $row['content']; $timestamp = $row['timestamp'];$display_block = "$title, $content, $contact, $timestamp";}?><html><head><title>Megalomaniacs News</title></head><body><h1>Megalomaniacs Inc. Articles</h1><?php echo "$display_block"; ?><p><a href="main.html">Return to Menu</a></p></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
jsladek Posted November 10, 2006 Share Posted November 10, 2006 Maybe something more like this?[code]<title>Megalomaniacs News</title></head><body><h1>Megalomaniacs Inc. Articles</h1><?php$db_name = "newdb";$table_name = "news";$connection = @mysql_connect("db.blah.com", "johndoe", "blah") or die(mysql_error());$db = @mysql_select_db($db_name, $conection) or die(mysql_error());$sql = "SELECT*FROM $table_name ORDER BY id";$result = @mysql_query($sql, $connection) or die(mysql_error());while ($row = mysql_fetch_array($result)) { $id = $row['id']; $title = $row['title']; $content = $row['content']; $timestamp = $row['timestamp'];$display_block = "$title, $content, $contact, $timestamp";echo "$display_block";}?><p><a href="main.html">Return to Menu</a></p></body></html>[/code]I just quickly rearranged you code, I'm really not exactly sure what you are expecting but the way you have it it looks like you will only get the last record in your databaseRegards,John Sladek Quote Link to comment Share on other sites More sharing options...
jeaker Posted November 10, 2006 Author Share Posted November 10, 2006 Thanks for the advice, finally got it working. 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.