View Single Post
  #2 (permalink)  
Old 06-25-09, 07:57 PM
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
Assuming the mysql table has two fields (username,picture).
And $user contains the value of the username to search for (ishmell),
$table contains the name of the mysql table and
$limit contains the total number of results to return (initially set to 2).
Change the value of $limit to the maximum number of pictures you want displayed.

Also assuming there can be multiple entries for username with different values for picture,
and you want the pictures to be displayed horizontally,
then this code will do what you want.

Note: The picture files must be stored on the server and the name of the picture files (including the path if applicable) must be stored in the picture field in the mysql table.

Also note: I am displaying the results in a table, but you can display them any way you want.
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. //

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());
?>
<html>
<head>
<title></title>
<style>
body{background:#000;}
table
{
 background:#aaf;
 border:4px solid #00f;
 }
</style>
</head>
<body>
<?php
if($results)
{
 echo 
"<table cellspacing='8' cellpadding='0'><tr>";
 while(
$row mysql_fetch_assoc($results))
 {
  echo 
"<td><img src='".$row["picture"]."' alt='".$row["picture"]."' width='100px' height='100px' /></td>";
  }
 echo 
"</tr></table>";
 }
?>
</body>
</html>
__________________
Jerry Broughton

Last edited by job0107; 06-25-09 at 08:09 PM.
Reply With Quote