Hi,
I am builing my first website with PHP and MySQL and I am running into some problems.
The website is built in DreamweaverCS4 using a lot of AP Div elements with fixed positions. Filling each element seperately is easy, but
So, for one page, I need to select the 5 latest items and display them on the website. It is kind of like a blog site, so the newest item needs to be displayed first. I want to try several nested 'if' statements in a loop, but I get the message: "Warning: extract() [function.extract]: first argument should be an array".
Also, I get the oldest item on top, not the newest. Using ORDER BY DESC didn't help.
Can anyone find my errors, or perhaps has a better way of doing these things? (For another page I need to be able to shuffle content around the web page, all being placed in specific AP Div elements)
here's the code:
<?php
include ("login.inc");
$cxn = mysqli_connect($host,$user,$password,$dbname)
or die ("Can't connect to server");
$query = "SELECT NewsTitle,VolgNr,NewsText,DisplayDate FROM NewsItems ORDER BY 'VolgNr' LIMIT 5";
$result = mysqli_query($cxn,$query)
or die ("Couldn't execute select query: " . mysqli_error($cxn));
for ($i=0;$i<=5;$i++)
{
$row = mysqli_fetch_assoc($result);
extract($row);
if($i==0)
{
echo "<div id='apDiv136'>";
echo "<div id='apDiv137'></div>";
echo "<div class='verdana10' id='apDiv138'>$DisplayDate</div>";
echo "<div class='verdana10bold' id='apDiv139'>$NewsTitle</div>";
echo "<div class='verdana10' id='apDiv140'>$NewsText</div>";
echo "<div id='apDiv37'></div>";
echo "</div>";
}
else
{
if($i==1)
{
echo "";
}
else
{
if($i==2)
{
echo "";
}
else
if($i==3)
{
echo "";
}
else
if($i==4)
{
echo "";
}
}
}
}
?>