Daegalus Posted September 5, 2007 Share Posted September 5, 2007 Well im making a custom news system for a site im building, I don't like the ones already out there, and I've hit a roadblock and have 0 clue why its not working. <?php include('config.php'); $dbh = mysql_connect($mysql_server, $username, $password) or die("Unable to connect to MySQL"); mysql_select_db($database,$dbh) or die("Could not select first_test"); $query = "SELECT * FROM news ORDER BY id DESC LIMIT 15"; $result = mysql_db_query($database,$query,$dbh) or die("Error in query: $query. " . mysql_error()); while($row = mysql_fetch_row($result)) { ?> <tr> <td> <? echo $row{'title'} ?><br /><? echo $row{'date'} ?> - <? echo $row{'time'} ?> - Posted By: Admin </td> </tr> <tr> <td> <? echo $row{'body'} ?> </td> </tr> <br /> <br /> <br /> <? } mysql_close($dbh); ?> http://www.kuncheff.com:81/WAR/ is where I test it. and as you see, the normal text appears, but none of the items retrieved from the database appear. Any help would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/68015-solved-php-wont-retrieve-the-information-from-the-database/ Share on other sites More sharing options...
darkfreaks Posted September 5, 2007 Share Posted September 5, 2007 <?php echo $row['title']; ?><br /><?php echo $row['date']; ?> - <?php echo $row['time']; ?> - Posted By: Admin </td> </tr> <tr> <td> <?php echo $row['body']; ?> </td> </tr> <br /> <br /> <br /> <?php } mysql_close($dbh); ?> Quote Link to comment https://forums.phpfreaks.com/topic/68015-solved-php-wont-retrieve-the-information-from-the-database/#findComment-341897 Share on other sites More sharing options...
SJames Posted September 5, 2007 Share Posted September 5, 2007 <?php mysql_connect($hostname, $username, $password); mysql_select_db($dbname); $result = mysql_query("SELECT * FROM news ORDER BY ID"); print "<table>"; while($array = mysql_fetch_while($result)) { $title = $result['title']; $date = $result['date']; $time = $result['time']; $body = $result['body']; print <<<HERE <tr> <td> $title <br> -$date <br> -$time <br> -Posted by: Admin </td> </tr> <tr> <td> $body </td> </tr> HERE; } print "</table>"; mysql_close; ?> Quote Link to comment https://forums.phpfreaks.com/topic/68015-solved-php-wont-retrieve-the-information-from-the-database/#findComment-341898 Share on other sites More sharing options...
Daegalus Posted September 5, 2007 Author Share Posted September 5, 2007 Nope doesn't work, I applied your changes, and it still results in the same. This the current code with corrections: <?php include('config.php'); $dbh = mysql_connect($mysql_server, $username, $password) or die("Unable to connect to MySQL"); mysql_select_db($database,$dbh) or die("Could not select " + $database); $query = "SELECT * FROM news ORDER BY id DESC LIMIT 15"; $result = mysql_db_query($database,$query,$dbh) or die("Error in query: $query. " . mysql_error()); while($row = mysql_fetch_row($result)) { ?> <tr> <td> <?php echo $row['title'] ?><br /><?php echo $row['date'] ?> - <?php echo $row['time'] ?> - Posted By: Admin </td> </tr> <tr> <td> <?php echo $row['body'] ?> </td> </tr> <br /> <br /> <br /> <?php } mysql_close($dbh); ?> Quote Link to comment https://forums.phpfreaks.com/topic/68015-solved-php-wont-retrieve-the-information-from-the-database/#findComment-341899 Share on other sites More sharing options...
darkfreaks Posted September 5, 2007 Share Posted September 5, 2007 um try using ; after each echo statement? Quote Link to comment https://forums.phpfreaks.com/topic/68015-solved-php-wont-retrieve-the-information-from-the-database/#findComment-341901 Share on other sites More sharing options...
Daegalus Posted September 5, 2007 Author Share Posted September 5, 2007 arg, sorry, but even after i added them it didnt work. the site is updated with the latest changes, and still doesnt pull any information. And SJames, yours gives me an undefined for mysql_fetch_while. Quote Link to comment https://forums.phpfreaks.com/topic/68015-solved-php-wont-retrieve-the-information-from-the-database/#findComment-341902 Share on other sites More sharing options...
darkfreaks Posted September 5, 2007 Share Posted September 5, 2007 nvm Quote Link to comment https://forums.phpfreaks.com/topic/68015-solved-php-wont-retrieve-the-information-from-the-database/#findComment-341903 Share on other sites More sharing options...
Daegalus Posted September 5, 2007 Author Share Posted September 5, 2007 Sjames' code gives me Fatal error: Call to undefined function mysql_fetch_while() in /var/www/WAR/include/news.php on line 10 I changed it to mysql_fetch_row(), it loads the page, but everything is empty again. Quote Link to comment https://forums.phpfreaks.com/topic/68015-solved-php-wont-retrieve-the-information-from-the-database/#findComment-341904 Share on other sites More sharing options...
darkfreaks Posted September 5, 2007 Share Posted September 5, 2007 <?php include('config.php'); $dbh = mysql_connect($mysql_server, $username, $password) or die("Unable to connect to MySQL"); mysql_select_db($database,$dbh) or die("Could not select " + $database); $query = "SELECT * FROM news ORDER BY id DESC LIMIT 15"; $result = mysql_db_query($database,$query,$dbh) or die("Error in query: $query. " . mysql_error()); while($row = mysql_fetch_row($result)) { ?> <tr> <td> <?php echo ($row['title']); ?><br /><?php echo ($row['date']);?> - <?php echo ($row['time']); ?> - Posted By: Admin </td> </tr> <tr> <td> <?php echo ($row['body']) ;?> </td> </tr> <br /> <br /> <br /> <?php } mysql_close($dbh); ?> Quote Link to comment https://forums.phpfreaks.com/topic/68015-solved-php-wont-retrieve-the-information-from-the-database/#findComment-341906 Share on other sites More sharing options...
Yesideez Posted September 5, 2007 Share Posted September 5, 2007 http://us3.php.net/function.mysql-db-query That function is depreciated! Read the page and see what you need to use instead. Silly question but is there anything in the "news" table? Second, are the fields title, date and time exactly as shown in the table? Calling a field "Title" and accessing by "title" will give you empty results. Quote Link to comment https://forums.phpfreaks.com/topic/68015-solved-php-wont-retrieve-the-information-from-the-database/#findComment-341907 Share on other sites More sharing options...
Daegalus Posted September 5, 2007 Author Share Posted September 5, 2007 http://us3.php.net/function.mysql-db-query That function is depreciated! Read the page and see what you need to use instead. Silly question but is there anything in the "news" table? Second, are the fields title, date and time exactly as shown in the table? Calling a field "Title" and accessing by "title" will give you empty results. Ok i used the new one, and i checked everything field titles are right and everything. there is data in the news table. With every new addition, the code does add another line of " - - Posted by: Admion." still no go. Quote Link to comment https://forums.phpfreaks.com/topic/68015-solved-php-wont-retrieve-the-information-from-the-database/#findComment-341913 Share on other sites More sharing options...
darkfreaks Posted September 5, 2007 Share Posted September 5, 2007 <?php $result = mysql_query($database,$query,$dbh) or die("Error in query: $query. " . mysql_error());?> Quote Link to comment https://forums.phpfreaks.com/topic/68015-solved-php-wont-retrieve-the-information-from-the-database/#findComment-341916 Share on other sites More sharing options...
Daegalus Posted September 5, 2007 Author Share Posted September 5, 2007 <?php $result = mysql_query($database,$query,$dbh) or die("Error in query: $query. " . mysql_error());?> mysql_query only requuires the query in it. Also i got it working with your help guys, thanks. I changed the mysql_fetch_row() (since its not part of mysql_query) to mysql_fetch_assoc, and it worked instantly. Thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/68015-solved-php-wont-retrieve-the-information-from-the-database/#findComment-341918 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.