
06-26-09, 01:36 AM
|
 |
Community Liaison
|
|
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
|
|
That's real easy.
Store all 32 image file names in an array.
These will be the default images in case no image file names are returned from the database.
Then replace the image file names in the array with the image file names returned from the query.
Like this:
PHP Code:
<?php $user = "ishmell"; // $user can be loaded through $_POST or $_GET or even a $_SESSION variable. // $limit = 2; // Set $limit to the maximum number of pictures you want displayed. //
$host = "localhost"; // Enter mysql host address here. // $username = "root"; // Enter mysql username here. // $password = ""; // Enter mysql password here. // $db = "test"; // Enter mysql database name here. // $table = "user"; // Enter mysql table name here. //
$images = array("img1.jpg","img2.jpg","img3.jpg","img4.jpg","img5.jpg","img6.jpg","img7.jpg","img8.jpg","img9.jpg","img10.jpg","img11.jpg","img12.jpg","img13.jpg","img14.jpg","img15.jpg","img16.jpg","img17.jpg","img18.jpg","img19.jpg","img20.jpg","img21.jpg","img22.jpg","img23.jpg","img24.jpg","img25.jpg","img26.jpg","img27.jpg","img28.jpg","img29.jpg","img30.jpg","img31.jpg","img32.jpg"); $count = 0;
mysql_connect($host,$username,$password) or die(mysql_error()); mysql_select_db($db) or die(mysql_error());
$sql = "SELECT * FROM $table WHERE username = '$user' LIMIT $limit"; $results = mysql_query($sql) or die(mysql_error()); if($results) { while($row = mysql_fetch_assoc($results)) { $images[$count] = $row["picture"]; $count++; } } ?> <html> <head> <title></title> <style> body{background:#000;} .img_container { float:left; padding:4px; border:4px solid #00f; background:#aaf; } .img_css { width:100px; height:100px; margin:4px; } </style> </head> <body> <div class="img_container"> <?php $count = 0; for($i=0;$i<count($images);$i++) { echo "<img class='img_css' src='".$images[$i]."' alt='".$images[$i]."' />"; $count++; if($count > 7){echo "<br />";$count=0;} } ?> </div> </body> </html>
__________________
Jerry Broughton
Last edited by job0107; 06-26-09 at 02:03 AM.
|