Xager Posted August 9, 2007 Share Posted August 9, 2007 Sorry, but I dont know much PHP at the moment. I am trying to put a basic News Section into my website, I found a tutorial for it <a href="http://www.beginnersphp.co.uk/news.php">HERE</a>. I followed it as best I could and got almost what I wanted. I just have one problem, well, I think its just one problem. When loading my index.php to display my News items it doesnt all show up, only the author and submitted shows, there are spaces for the Title Descriptions and URL but no text shows up. Here is my code: index.php <?php include("config.php"); //this is our SQL query , note we are ordering by the submitted date //and setting a limit of ten items $query = "SELECT * FROM news ORDER BY submitted DESC LIMIT 10"; //execute the query $result = mysql_query($query); //start creating our table echo ("<table border='0' width='90%'>"); //loop through rows in the database while ($rows = mysql_fetch_row($result)) { //in the first row we display the title ($rows[1]) and the author $rows[3] echo ("<tr bgcolor='violet'><td>$rows[1]</td><td>author : $rows[3]</td></tr>"); //in the next row we display the description which is $rows[2] echo ("<tr><td colspan='2' bgcolor='lavender'>$rows[2]</td></tr>"); //finally we display the url which is rows[5] and the submitted date which is rows[4] echo ("<tr bgcolor='violet'><td><a href='$rows[5]'>$rows[5]</a></td><td>Submitted on : $rows[4]</td></tr>"); } //finish or table echo "</table>"; ?> and add.php (news item submission form) <?php include("config.php"); //create or query inserting the appropriate values into the mysql //table $query = "INSERT INTO news(title , description ,author , submitted , url) VALUES('$title','$desc','$author', now(),'$url')"; //execute query and store result as variable $result = mysql_query($query); //displays a message , you could redirect back to the form //instead , if you wished echo ("news item entered"); ?> <form action ="add.php" method = "post"> <table> <tr><td>Title</td><td><input type="text" name="title"></td></tr> <tr><td>Author</td><td><input type="text" name="author"></td></tr> <tr><td>Description</td><td><textarea name="desc" rows="5" cols="50" wrap="VIRTUAL"></textarea></td></tr> <tr><td>URL</td><td><input type="text" name="url"></td></tr> <tr><td><input type="submit"></td><td><input type="reset"></td></tr> </table> </form> thanks for any answers. Regards, Xager. Quote Link to comment https://forums.phpfreaks.com/topic/64074-beginner-help/ Share on other sites More sharing options...
emehrkay Posted August 9, 2007 Share Posted August 9, 2007 Id suggest changing mysql_fetch_row to mysql_fetch_assoc because, as in your example, you can only reference your array by number. with assoc, you can reference it by the name of the column. so youd go from $rows[3] to $rows['column_name'] - thats just to make things a little easier for you, the programmer. looking at your code i do nto see why $row[4] or whatever are not showing up. a simple way to check to see what the output is would be to print_r($rows); inside of your loop while ($rows = mysql_fetch_row($result)) { echo "<pre>", print_r($rows), "</pre>"; //just comment out the display code for now } this will show you what you are returning from the database. good luck Quote Link to comment https://forums.phpfreaks.com/topic/64074-beginner-help/#findComment-319322 Share on other sites More sharing options...
emehrkay Posted August 9, 2007 Share Posted August 9, 2007 http://us3.php.net/manual/en/function.mysql-fetch-assoc.php Quote Link to comment https://forums.phpfreaks.com/topic/64074-beginner-help/#findComment-319323 Share on other sites More sharing options...
Xager Posted August 9, 2007 Author Share Posted August 9, 2007 OK, I did what you said and this is what i get Array ( [0] => 1 [1] => [2] => [3] => [4] => 2007-08-09 [5] => ) 1 Array ( [0] => 2 [1] => [2] => [3] => [4] => 2007-08-09 [5] => ) 1 I understand that only the Date is showing, I just dont know how to fix it. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/64074-beginner-help/#findComment-319335 Share on other sites More sharing options...
emehrkay Posted August 9, 2007 Share Posted August 9, 2007 that means that only the date is in the database, there must be an issue with your input. focus on debuggin that. Quote Link to comment https://forums.phpfreaks.com/topic/64074-beginner-help/#findComment-319377 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.