theredqueen
Programmer
Hey there, i'm trying to program a news script to retrieve the news items from a database, so i don't have to code the html for each one. I've done stuff in php before, but not with my database. Truth be told, I'm not entirely competent in it.
So anyway, i'd like to display the last 5 entries to the news table. I have 3 variables in the table, id, title and message.
so, this is all ok, but i think it's not what i need...
<?php
/* Connecting, selecting database */
$link = mysql_connect("localhost", "***mydb", "***mypass"
or die("Could not connect"
mysql_select_db("***mydb" or die("Could not select database"
/* Performing SQL query */
$query = "SELECT * FROM news";
$result = mysql_query($query) or die("Query failed"
then i wanted to print the variables as is into my html...
print " <table width=\"718\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
print " <tr> \n";
print " <td width=\"176\" height=\"15\"></td>\n";
print " <td width=\"372\" valign=\"top\"><font size=\"2\">$title</font></td>\n";
print " <td width=\"170\"></td>\n";
print " </tr>\n";
i know this won't work as is, and i think i need to use
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
but to be honest, it confuses me. is there no way i can retrieve the variables then just refer to them in my html as above?
i'm also still a bit confused about how i'm going to get just the last 5, i was guessing something with some thing like the last id -5 or soemthing, then i'd have to link at the bottom to a page with -5 to -10.
i appreciate this is a number of fairly lame questions, but would also appreciate any help! i am not friends with php =D
So anyway, i'd like to display the last 5 entries to the news table. I have 3 variables in the table, id, title and message.
so, this is all ok, but i think it's not what i need...
<?php
/* Connecting, selecting database */
$link = mysql_connect("localhost", "***mydb", "***mypass"
or die("Could not connect"
mysql_select_db("***mydb" or die("Could not select database"
/* Performing SQL query */
$query = "SELECT * FROM news";
$result = mysql_query($query) or die("Query failed"
then i wanted to print the variables as is into my html...
print " <table width=\"718\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
print " <tr> \n";
print " <td width=\"176\" height=\"15\"></td>\n";
print " <td width=\"372\" valign=\"top\"><font size=\"2\">$title</font></td>\n";
print " <td width=\"170\"></td>\n";
print " </tr>\n";
i know this won't work as is, and i think i need to use
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
but to be honest, it confuses me. is there no way i can retrieve the variables then just refer to them in my html as above?
i'm also still a bit confused about how i'm going to get just the last 5, i was guessing something with some thing like the last id -5 or soemthing, then i'd have to link at the bottom to a page with -5 to -10.
i appreciate this is a number of fairly lame questions, but would also appreciate any help! i am not friends with php =D