View Single Post
  #7 (permalink)  
Old 06-27-09, 09:15 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
First of all you didn't mention anything about having an id field.
And secondly, you didn't learn anything.

I have no idea if the id's are different for each record, so I created another array to store the id.
But sense you didn't specify that you have an id, then I am storing the username in the array instead.
You can change that to suit what ever you need.
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");
$ids = array();
$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"];
  
$ids[$count] = $row["username"];
  
$count++;
  }
 }
?>
<html>
<head>
<title></title>
<style>
body{background:#000;}
.img_container
{
 float:left;
 margin-left:17%;
 margin-top:8%;
 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 
1;
 
$images_per_row 8;
 for(
$i=0;$i<count($images);$i++)
 {
  echo 
"<a href='page.php?id=iteminfo&item=".$ids[$i]."' target='_blank'><img class='img_css' src='".$images[$i]."' alt='".$images[$i]."' /></a>";
  
$count++;
  if(
$count $images_per_row){echo "<br />";$count=1;}
  }
 
?>
</div>
</body>
</html>
__________________
Jerry Broughton
Reply With Quote