FireFox! The PHP Forum Loans and Credit
Panama Web Design for Hire Free Insurance Quotes!
Web Hosting Advertise Here $10 a Month Designer Children
Never Pay Taxes Again HGH Domain name registration
Web Hosting and Dedicated Servers Insurance Affordable web-hosting


HomeWatched TopicsRegisterSearchDirectory
FAQMemberlistUsergroupsLog inStoresItemsBank
Google

Reply to topic Page 1 of 1
image retrival problem whith pageing
Message  
Reply with quote
Post image retrival problem whith pageing 
Hi,
I am new to PHP

please help me on this.
I have created a table to insert images from a form into the mysql database and it is done successfully, when i have many records and want to search i created a search form to with pageing to search name and image
the text data that is name changes when i click the link 1 2 .... but image does not change...
 what i want to do is that text data and image should change as i click the links ...

please help me...
this is the table that i use to store images in
 
==========================
table------------------------------------------------
 
CREATE TABLE  image_table ( ImageId int(10) NOT NULL auto_increment,
name varchar2(35) default null,
imgdata longblob, filetype varchar(32) default NULL,
  PRIMARY KEY  (ImageId) );
 
-----------------------------------------------------------------------------------------------------------------------------
code to insert the image in to the table
 
 insert_image.html
 
 <html>
      <head>
      <title>Add Image</title>
      </head>    
      <body>
      
      <form action="insert_image.php" method="post" enctype="multipart/form-data" name="form1">
  Name&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="name" size="20" />
  <br>
   Please&nbsp; browse to upload your Photo:
      <input type="file" name="file" size="20">
      <input type="hidden" name="MAX_FILE_SIZE" value="100000">
      <input type="submit" name="Submit" value="Submit">
      </form>
      </body>
      </html>
   -----------------------------------------------------------------------
  
   the code for  insert_image.php which is called by insert_image.html
  
   <?php
      if ($_POST['Submit'])
   {
        if ($_POST['MAX_FILE_SIZE'] >= $_FILES['file']['size'])
  {
          
          $con = mysql_connect("localhost","root","password");
     if (!$con)
     {
      die('Could not connect: ' . mysql_error());
     }
          mysql_select_db("test");
        $photo = addslashes(fread(fopen($_FILES['file']['tmp_name'], "r"),$_FILES['file']['size']));
$query = sprintf("INSERT INTO
image_table(
  name,
  imgdata,
  filetype
)
VALUES(
'$_POST[name]',
'%s', '%s')", $photo, $_FILES['file']['type']);
           if (mysql_query($query))
     {
            echo "Your files is successfully store in database";
           }
     else
     {
            echo " ".mysql_error();
           }
          }  
    else
    {
           echo "The file is bigger than the allowed size please resize";
          }
        }
  
  mysql_close($con);
      ?>
------------------------------------------------------------------------------------------------------------------------------

 
this is the code to retrive image from database ....
 name is changing when i click the page 1 2 3 link... but  my problem is that image is not changing...

this code is saved as image_show.php

-------------------------------------------------------------------------------------------------------------
this is the code  for image_search.html
 

<HTML>
<HEAD><TITLE></TITLE></HEAD>
<BODY>
<CENTER>
<BR><BR>
<FORM NAME="Search" ACTION="image_search.php" METHOD="POST">
<INPUT TYPE="TEXT" NAME="search_name">
<INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="Search">
</FORM>
</CENTER>
</BODY>
</HTML>

--------------------------------------------------------------------------------------------------------------------------------
this is the code for image_search.php which is called by image_search.html
<?php
// Connect to database
$search_name=$_REQUEST[search_name];

$errmsg = "";
$con = mysql_connect("localhost","root","password");

if (!$con) {
        $errmsg = "Cannot connect to database";
        }
@mysql_select_db("test");

// Find out about latest image
//$uid = 0;
$query ="select  name,  imgdata from image_table where name LIKE '%$search_name%' ORDER BY name";
$SearchResult=mysql_query($query) or die(mysql_error());

$NumberOfResults=mysql_num_rows($SearchResult);
$Limit = 5; //Number of results per page
$NumberOfPages=ceil($NumberOfResults/$Limit);

$page=$_GET["page"]; //Get the page number to show
If($page == "") $page=1;

$SearchResult=mysql_query("SELECT name,imgdata FROM image_table WHERE name LIKE '%$search_name%' ORDER BY name LIMIT " . ($page-1)*$Limit . ",$Limit")  or die(mysql_error());


While($row = mysql_fetch_array($SearchResult))
 {
$name  = $row[name];
$bytes = $row[imgdata];
if ($_REQUEST[abc] == 1) {
       header("Content-type: image/jpeg");
       print $bytes;
        exit ();
        }
echo "</table>";
}

$Nav="  ";

For($i = 1 ; $i <= $NumberOfPages ; $i++) {
If($i == $page) {
$Nav .= "<B>$i</B>";
}Else{
$Nav .= " "."<A HREF=\"image_show.php?page=" . $i . "&search_name=" .urlencode($search_name) . "\">$i</A>"." ";
}
}

//mysql_close($con);
?>
</body>
</html>
<html><head>
<title></title>
<body bgcolor=white><h2>Picture</h2>
<p><font color=red>
  <?php  $errmsg ?>
  </font></p>
<center>
  <p>&nbsp;</p>
  <table width="675" height="295" border="1">
    <tr>
      
      <td width="393" height="289">

<?php echo  "Name: "." ".$name."<br>"; ?>

</td>
      <td width="266"><img src=?abc=1 height = 285 width=266></td>
 
    </tr>
  </table>
<?php  Echo "<br>Pages".  $Nav ."</center>"; ?>

</center>
</body>
</html>


-------------------------------------------------------------------
Regards
 
Monty sen

View user's profile Send private message Send e-mail
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
  



Google

FireFox! The PHP Forum Loans and Credit
Panama Web Design for Hire Free Insurance Quotes!
Web Hosting Advertise Here $10 a Month Designer Children
Never Pay Taxes Again HGH Domain name registration
Web Hosting and Dedicated Servers Insurance Affordable web-hosting


Web Design by PlatinumShore.com & Web Hosting by TradeWebHosting.com