Trying to learn some more PHP and MySQL here now, and I'm having problems understanding how this works. I do know other languages, so I'm hoping I will understand PHP much better if I just can get some help with this example:
I have a table called files. This contains 3 rows (3 files), where I've defined fileID, thumbURL, fullRUL, and stuff like that.
on my webpage I want to fetch this whole list of items/files, and do a for loop to display them all.
This is my PHP code, which of course repeats itself 3 times but it displays the same information, because it only uses the same row:
<div id="contentWrapper">
<?php
for($i = 0; $i < $numItems; $i++){
echo "<div id='contentItem'>";
echo "<a href='".$row['fullURL']."' title='".$row['description']."'><img src='". $row['thumbURL']."' width='200px' height='150px' /></a>";
echo "</div>";
}
?>
</div>
This is the code where I get the data from the database:
<?php
$db = mysql_connect("localhost", "xxxxx", "xxxxx");
mysql_select_db("login",$db) or die("Kan ikke koble til databasen");
$filesSQL = mysql_query("SELECT * FROM files");
$numItems = mysql_num_rows($filesSQL);
$sql="SELECT * FROM `files` WHERE fileID=1";
$result=mysql_query($sql);
if (false === $result) {
echo mysql_error();
}
$row=mysql_fetch_array($result, MYSQL_BOTH);
?>
The current example here does only fetch the firsst row and stores that in an array, so thats why I get the same values on all 3 items.
But I've tried using $filesSQL[$i]['thumbURL'] and other similar methodes, but I cant get it to work.
I guess this is a very basic question, so I'm hoping for an answer that will help me understand how to work with databases, arrays and displaying it.
I can easily do this in Actionscript3 or other languages, but not in php! =S
Thanks! =D