Jump to content

problem with display images


swethak

Recommended Posts

 

 

  Hi,

 

  i wrote the code for to display the images taken from database.When i click on the each images it goes to next page and displayed in that page.But my requirement is to when click on the image that image full size displayed on the same page. Plz tell that what's the problem in my code and give the solution for that.

 

 

viewimages.php:

 

<?php

// Your host, 99% of the time it's localhost.

$db_host = 'localhost';

// Your username for MySQL.

$db_user = 'root';

// Your password for MySQL.

$db_pass = 'root';

// And your given name for the database.

$db_name = 'rainlist';

 

// The database connection.

$con = mysql_connect($db_host, $db_user, $db_pass);

if(!$con) {

die("Cannot connect. " . mysql_error());

}

$dbselect = mysql_select_db($db_name);

if(!$dbselect) {

die("Cannot select database " . mysql_error());

}

$result1 = mysql_query("SELECT * from pix");

$num_rows=mysql_num_rows($result1);

?>

<table border="1" bggroung="black">

<?

if(isset($_GET["skip"])){

$skip=$_GET["skip"];

}else{$skip=0;}

$i=0;

$ps=$num_rows;

$endlimit=$skip+$ps;

$result = mysql_query("SELECT * from pix LIMIT $skip, $ps");

$rowCount = mysql_affected_rows();

if($rowCount==0){

?>

           

              <td align="center" backgroundcolor="black" ><br /><br />No Images uploaded.<br /><br /></td>

         

            <?php

}else {?>

            <?php $rc=mysql_num_rows($result);

$rc=$rc-$skip;

if ($rc>=$ps){

$i=$ps;

}else{

$i=$rc;

}

?>

<tr align="center" valign="middle">

            <?

$row_count = 1;

while ($row = mysql_fetch_array($result)) {

$pid=$row['pid'];

$imgdata=$row['imgdata'];

?>

<td bgcolor="black"><img src="image2.php?id=<?=$pid?>" width="100" border="0">

</td>

<?php

if($row_count % 9 == 0)

 

echo('</td></tr><tr align="center" valign="middle" >');

 

$row_count++;

}//while

}//else

?>

</table>

 

 

image2.php :

 

 

<?php

mysql_connect("localhost", "root", "root") or die(mysql_error());

mysql_select_db("rainlist");

$result = mysql_query(sprintf("SELECT * from pix WHERE pid = %d", $_GET['id']));

$row = mysql_fetch_array($result);

$image=$row['imgdata'];

header("Content-type: image/jpeg");

echo $image;

?>

 

Link to comment
https://forums.phpfreaks.com/topic/109854-problem-with-display-images/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.