i have displayed all members in my site including there photos,which they uploaded.
this is the view.php
which image will appear for everymember who uploaded photo.
<?
echo"<img src=retrieve.php?id=$userid width=200 height=150>";
?>

retrieve.php

<?php
//PHP code (for images.php)

if(isset($_GET)){
$id = $_GET;

// Connecting to a MySql Database
include"config.php";
//selecting image

$query = "SELECT * FROM image WHERE userid = '$id'";
$result = mysql_query($query);
$count=mysql_num_rows($result);
if($count==1){
if($row = mysql_fetch_array($result)){
$id=$row;
$image = $row;
$filetype = $row;

header("Content-type: ". $filetype);
echo $image;

}


}


?>

Now i need to know what what can i do,so that for those member who dont have photo
a certain image will appear,indicating that there is no photo for that profile.
Any help will be appreciated.

Recommended Answers

All 3 Replies

i would add an else statement to the if that determines if the number of rows is one.

in that else statement i would open an image file that contains the "no profile image" image. read its contents and echo it out.

<?php
//PHP code (for images.php)

if(isset($_GET)){
$id = $_GET;

// Connecting to a MySql Database
include"config.php";
//selecting image

$query = "SELECT * FROM image WHERE userid = '$id'";
$result = mysql_query($query);
$count=mysql_num_rows($result);
if($count==1){
if($row = mysql_fetch_array($result)){
$id=$row;
$image = $row;
$filetype = $row;

header("Content-type: ". $filetype);
echo $image;

}


}else{


$chek = "SELECT * FROM picha WHERE user = 'sam'";
$chaz = mysql_query($chek);

if($row = mysql_fetch_array($chaz)){
$id=$row;
$image = $row;
$filetype = $row;


header("Content-type: ". $filetype);
echo $image;

}


}


?>
i used the code above as u said,but rather i created another table,there i inserted a photo with username 'sam'.so that it will appear if no image for that member.
but it doesnot work all the same.

it is now working,i forgot to close
if(isset($_GET)) at the end.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.