hello friends,

I want to display only those images which are checked.
I had tried so many times but no use.
when I checked any images. it displays only last image.
can any tell me where is the problem
here is the code.

display.php

<?php
$i=0;
$connect = mysql_connect('localhost','root','') or die("Not connected");
$select = mysql_select_db('demo_data', $connect) or die("Not selected");
//$result = "select * from 'demo_data'.'photo_info' ";
$count = mysql_query("select * from photo_info ");
//$record = mysql_num_rows($count);
//if($record >0){
while($r= mysql_fetch_array($count)){
$i++;
$name = $r;
echo '<img src= " '.$name.'" />';
?>
<form action="new.php" method="post" >
<input type="checkbox" name="selectimg[]" value="<?php echo $i; ?> "/>
<?php }
?>
<input type="submit" value="submit" name="fsub" />
</form>

show.php

<?php //mysql_close($hostn);
require_once ("display.php");
if(isset($_POST)){
$check = $_POST;
//$box = $check;
if(empty($check)){
echo "Not getting";
}
else{
$count = count($check);
$x=0;
for($i=0; $i<$count; $i++){
$v = $check[$i];
while($x < $count){

$x++;
echo '<img src= "'.$name.'" />' ;
}
}
}
}
?>

Member Avatar for rajarajan2017
<input type="checkbox" name="selectimg[]" value="<?php echo $i; ?> "/>

Look into the $i value it only sets the last value of i, bcoz it executes after the first php statement completed.

<input type="checkbox" name="selectimg[]" value="<?php echo $i; ?> "/>

Look into the $i value it only sets the last value of i, bcoz it executes after the first php statement completed.

thanx for ur reply. but i have check $i value and it correctly showing the checked value.

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.