Jump to content

[SOLVED] how can I approach this loading images problem from the database


shadiadiph

Recommended Posts

mm very tricky question I think.

I have a edit images page but I am at a complete loss as to where to go from here any input would be appreciated the page that displays them calls them from another php page the images are stored in a database. I want to display a link edit delete under the images where an image is displayed. can i put anything on the editpic.php page here are the two codes I am running been sitting here thinking about this for hours can't think

Any ideas??

 

html

<table class="addpix">
<tr><td><img src="editpic1.php?adid=<?=$id?>" /></td>
<td><img src="editpic2.php?adid=<?=$id?>" /></td>
<td><img src="editpic3.php?adid=<?=$id?>" /></td>
<td><img src="editpic4.php?adid=<?=$id?>" /></td></tr>
</tr>
</table>

 

editpic1.php code

 

<? 
session_start();
error_reporting(7);
require("../global/admin_functions.php");
$sid = $_SESSION['LOGINID'];
if($sid!="")
{
if (isset($_GET['adid'])) {
    $query = "SELECT thumbnail1,thumbnailtype1,description1 FROM zloads where intProductID=".$_GET['adid'];
    $result = mysql_query($query);
    if (mysql_num_rows($result) ==1) {
        $data = mysql_result($result,0,"thumbnail1"); 
        $type = mysql_result($result,0,"thumbnailtype1"); 
        Header( "Content-type: $type");
        print $data;

    }  
}
header("Content-Type: image/png"); 
$file = ('../../pix/noimage.png');
$source = (fread(fopen($file, "r"), filesize($file)));
print ($source);
}
?>

 

Link to comment
Share on other sites

so it is probably safer to call the image directly from the database to the screen instead of using editpic1.php to call it correct that way anyone viewing the source wouldn't see it right.

 

At the moment I am working on trying to embed the code of editpic1.php into the html but it isn't working getting the error i had alot while making the editpic1.php Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource.

 

mm i went through hours trying to get that just to work oh well back to the drawing board.

Link to comment
Share on other sites

for example this script works fine on the seperate editpic.php but when i try to use it in the html page as

 

<tr><td>
<?
    $query = "SELECT thumbnail1,thumbnailtype1 FROM zloads where intProductID=$adid";
    $result = mysql_query($query);
    if (mysql_num_rows($result) ==1) {
        $data = mysql_result($result,0,"thumbnail1"); 
        $type = mysql_result($result,0,"thumbnailtype1"); 
        Header( "Content-type: $type");

  }

?>
<img src="<?=$data?>" />
</td>

 

keeps getting that sql-num_rows error???

Link to comment
Share on other sites

now it seems to have changed to

 

Warning: Cannot modify header information - headers already sent by (output started at /home/hmtcompa/public_html/user/myaccount/updatepix.php:13) in /home/hmtcompa/public_html/user/myaccount/updatepix.php on line 152
ÿØÿàJFIFÿþ\‚ÛL³šöä.@A'• 3òç kä'pJúÎÖ^ç½4Ú²½š»wvÓ¹û¾3WçJ:9nùVîVºÚÞ÷kh¬|…g£ßÜ(2i³Ë…Â%‰\d[ ÜzÎ è,ü3 “ZÝA»îïŠBU€ÏðäìÏ X‚@èM|‹ð™õ¼?ñ£Å7?üSãjº¾±‰ZC™ÒoìÛ¨¢J_R£ì)GÚ?†Nœå)^9ye)L`ò¨á+äø§,½} //alot more of this//

 

seems like it is almost reading it??

Link to comment
Share on other sites

been through the whole document and removed any other header comments but the error says the output was started by the one line diectly above print $data;????

 

<tr><td>
<?

    $query = "SELECT thumbnail1,thumbnailtype1 FROM zloads where intProductID='$id'";
    $result = mysql_query($query);
    if (mysql_num_rows($result) ==1) {
        $data = mysql_result($result,0,"thumbnail1"); 
        $type = mysql_result($result,0,"thumbnailtype1"); 
        header( "content-type: $type " );
        print $data;
  
  }

?>
</td>

Link to comment
Share on other sites

ok so I have moved the script to the top of the page and if i use print $data above the head it only shows the image on the page and none of the other html below it?

 

if i put print $data; further down the page it writes rubbish like before the binary stuff how can i get around this?

Link to comment
Share on other sites

I had an idea but it wont work the way I have laid it out because it is asking the if question before it has had a chance to get the data I am trying to display an image with delete edit if there is an image there $result="valid" and if there isn't an image display $result='invalid, but I know I have it all the wrong way round if anyone can help with this it would be appreciated or any ideas thanks.

 

editpic2.php

 

<? 
session_start();
error_reporting(7);
require("../global/admin_functions.php");
$sid = $_SESSION['LOGINID'];

if($sid!="")
{

if (isset($_GET['adid'])) {
    $query = "SELECT thumbnail2,thumbnailtype2 FROM zloads where intProductID=".$_GET['adid'];
    $result = mysql_query($query);
    if (mysql_num_rows($result) ==1) {
        $data = mysql_result($result,0,"thumbnail2"); 
        $type = mysql_result($result,0,"thumbnailtype2"); 
        Header( "Content-type: $type" );
        $result = "valid";
        return $result;
        print $data; 

    }  
}

header("Content-Type: image/png"); 
$file = ('../../pix/noimage.png');
$source = (fread(fopen($file, "r"), filesize($file)));
$result = "invalid";
return $result;
print ($source);

}
?>

 

html

<table class="addpix">

<? if ($_GET["result"]=="valid"){ ?>
<td><img src="editpic1.php?adid=<?=$id?>" /><br />
EDIT DELETE</td>
<?
} 
if ($_GET["result"]=="invalid"){?>
<td><img src="editpic1.php?adid=<?=$id?>" /></td>
<?
}
?>
<? if ($_GET["result"]=="valid"){?>
<td><img src="editpic2.php?adid=<?=$id?>" /><br />
EDIT DELETE</td>
<?
}
?>
<? if ($_GET["result"]=="invalid"){?>
<td><img src="editpic2.php?adid=<?=$id?>" /></td>
<?
}
?>

 

please excuse my terrible coding

 

 

Link to comment
Share on other sites

would it be better to somehow create a temporary image from the image in the database first or would i just be going around in circles back to square one. I want to get the image from the database and where there is an image stored in the database make the display page also give an edit delete option this is very confusing I can't believe it is impossible as suggested??

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.