A bit of Newb help please (php / SQL)
Posted: Sun Feb 26, 2012 3:53 pm
Hi all,
I'm trying to build a very basic news system.
I've got a table in SQL that has a few columns:
headline, article, pic1, date, number.
They're all varchar and all hold text except "number" which increments per entry and "date" which is set by "now()" in the form.
I want to pull out the data in a certain way and so far I've got this far:
This prints the whole lot the the screen, in descending order, as you'd expect.
Now I want to be a bit snazzier and assign each entry a variable name so the data on row 1 would end up as:
$headline1= (whatever is in the table field "headline" on row 1).
$article1= (whatever is in the table field "article" on row 1)
$picture1= (whatever is in the table field "pic1" on row 1)
etc etc etc
I want to do this for the first thirty entries and I'm guessing there's a loop of some sort I can use to do it but after
a couple of hours of trying I'm turning here for help
I want eventually to turn the whole lot into flashVars if that helps but just getting the basics working would be a big step forward right now.
All and any tips / advice / links / code very much appreciated.
Best wishes
Monty
I'm trying to build a very basic news system.
I've got a table in SQL that has a few columns:
headline, article, pic1, date, number.
They're all varchar and all hold text except "number" which increments per entry and "date" which is set by "now()" in the form.
I want to pull out the data in a certain way and so far I've got this far:
Code: Select all
include_once "../scripts/connect_to_mysql.php";
$result = mysql_query("SELECT * FROM articles ORDER BY number DESC");
while($row = mysql_fetch_array($result))
{
echo $row['number'] .$row['headline'] .$row['article'] ."news/images/" .$row['pic1'] . "<br>";
}
Now I want to be a bit snazzier and assign each entry a variable name so the data on row 1 would end up as:
$headline1= (whatever is in the table field "headline" on row 1).
$article1= (whatever is in the table field "article" on row 1)
$picture1= (whatever is in the table field "pic1" on row 1)
etc etc etc
I want to do this for the first thirty entries and I'm guessing there's a loop of some sort I can use to do it but after
a couple of hours of trying I'm turning here for help
I want eventually to turn the whole lot into flashVars if that helps but just getting the basics working would be a big step forward right now.
All and any tips / advice / links / code very much appreciated.
Best wishes
Monty
