Hello,
I am fairly new to PHP and am trying to display images in a table. I have found a script to which I have added my connection details which would in other scripts.
I created a table called images with columns called upload_time, src, and title, and stored for gif files into the table. The images are in the same folder as the PHP file.
SQL result
Host: sql103.beesimple.co.uk
Database: beesi_7131470_school
SQL query: SELECT * FROM `images` LIMIT 0, 30 ;
Rows: 5
src title upload_time
A-10Thunderbolt.gif A-10Thunderbolt.gif 2011-04-04 18:47:42
A-10Thunderbolt.gif A-10Thunderbolt.gif 2011-04-04 18:47:50
A-BSide.gif A-BSide.gif 2011-04-04 18:48:14
A-Centauro.gif A-Centauro.gif 2011-04-04 18:48:37
A-Maze.gif A-Maze.gif 2011-04-04 18:48:54
The PHP File is as follows:
<?php
//connect to MySQL; note we’ve used our own parameters- you should use
//your own for hostname, user, and password
$connect = mysql_connect("sql103.beesimple.co.uk", "XXX", "XXX") or
die ("Hey loser, check your server connection.");
mysql_select_db("beesi_7131470_school");
$pull_images = mysql_query("SELECT * FROM `images` ORDER BY `upload_time` ASC")
if( @mysql_num_rows( $pull_images ) > 0 ) {
echo '<<strong class="highlight">table</strong>>';
$count = 0;
while( $row = mysql_fetch_array( $pull_images ) ) {
if( $count == 0 ) {
echo "<tr><td>";
} else {
echo "<td>";
}
echo '<img src="' . $row['src'] . '" alt="' . $row['title'] . '" />';
if( $count == 3 ) {
echo '</td></tr>';
$count = 0;
} else {
echo '<td>';
$count++;
}
}
$cells_left = 4 - $count;
if( $cells_left > 0 ) {
$i = 0;
while( $i <= $cells_left ) {
echo '<td></td>';
$i++;
}
echo '</tr>';
}
echo '</table>';
} else {
echo "No <strong class="highlight">images</strong> <strong class="highlight">in</strong> the database.";
}
?>
Many thanks
Peter Jones


