Jump to content

[SOLVED] only showing a value if it equals something?


shadiadiph

Recommended Posts

Then that means you have an error in your query.

 

<?php 
require("global/admin_functions.php"); 

$query = "SELECT thumbnail3,thumbnailtype3 FROM zloads where intProductID=".$_GET['adid'];
$result = mysql_query($query) or die(mysql_error());
  if (mysql_num_rows($result) > 0) {

 

That is how it should be, run that and I bet you get an error in SQL query. If you need help to fix that post the error. If not fix it and it should work just fine.

Link to comment
Share on other sites

thanks premiso but now i am totally lost it was displayig something before and selecting an image each time even if it was wrong now it is saying.

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Link to comment
Share on other sites

<?php 
require("global/admin_functions.php"); 

if (isset($_GET['adid'])) {
    $query = "SELECT thumbnail3,thumbnailtype3 FROM zloads where intProductID=".$_GET['adid'];
    $result = mysql_query($query);
    if (mysql_num_rows($result) < 1) {
        $data = mysql_result($result,0,"thumbnail3"); 
        $type = mysql_result($result,0,"thumbnailtype3"); 
        Header( "Content-type: $type");
        print $data; 
        exit;
    }  
}

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

?>

 

Try that.

 

You should not query if $_GET does not have a variable in it. I would also do some data validation on the $_GET before using it in my query, but that is me.

Link to comment
Share on other sites

that shows only the noimage.png even in the area that has an image in showpic3.php

 

showpic3.php where there should be an image but it is showing the noimage.png

<?php 
require("global/admin_functions.php"); 

if (isset($_GET['adid'])) {
    $query = "SELECT thumbnail3,thumbnailtype3 FROM zloads where intProductID=".$_GET['adid'];
    $result = mysql_query($query);
    if (mysql_num_rows($result) < 1) {
        $data = mysql_result($result,0,"thumbnail3"); 
        $type = mysql_result($result,0,"thumbnailtype3"); 
        Header( "Content-type: $type");
        print $data; 
        exit;
    }  
}

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

?>

 

showpic4.php shows the noimage.png like it is supposed to as in thumbnail4 there is no image stored.

<?php 
require("global/admin_functions.php"); 

if (isset($_GET['adid'])) {
    $query = "SELECT thumbnail4,thumbnailtype4 FROM zloads where intProductID=".$_GET['adid'];
    $result = mysql_query($query);
    if (mysql_num_rows($result) < 1) {
        $data = mysql_result($result,0,"thumbnail4"); 
        $type = mysql_result($result,0,"thumbnailtype4"); 
        Header( "Content-type: $type");
        print $data; 
        exit;
    }  
}

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

that shows only the noimage.png even in the area that has an image in showpic3.php

 

It sounds to me like you are not populating the adid. That is why you are not getting the image.

 

http://www.yoursite.com/showpic3.php?adid=x

 

Replace the x with the product id and see what comes out.

 

As long as that has a value and the productid does indeed have a pic inside it should display just fine.

Link to comment
Share on other sites

could there be something wrong in the display page. id is gotten further up the page

$id = $row["intProductID"];

 

 

<table class="adpix">
<tr>
<td>
<img src="../showpic1.php?adid=<?=$id?>" />
</td>
<td>
<img src="../showpic2.php?adid=<?=$id?>" />
</td>
</tr>
<tr>
<td>
<img src="../showpic3.php?adid=<?=$id?>" />
</td>
<td>
<img src="../showpic4.php?adid=<?=$id?>" />
</td>
</tr>
</table>

Link to comment
Share on other sites

I know that some servers <?= is disabled so it is good practice to use

 

<?php echo $id; ?>

 

instead.

 

Not sure if that is the issue, but are you sure that $id is being populated from the database?

 

Post the code where the $id is being set, like that whole section of code.

Link to comment
Share on other sites

Sorry I feel like an idiot.

 

Try this:

<?php 
require("global/admin_functions.php"); 

if (isset($_GET['adid'])) {
    $query = "SELECT thumbnail3,thumbnailtype3 FROM zloads where intProductID=".$_GET['adid'];
    $result = mysql_query($query);
    if (mysql_num_rows($result) > 0) {
        $data = mysql_result($result,0,"thumbnail3"); 
        $type = mysql_result($result,0,"thumbnailtype3"); 
        Header( "Content-type: $type");
        print $data; 
        exit;
    }  
}

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

?>

 

Changed < 1 to > 0 in the mysql_num_rows part.

Link to comment
Share on other sites

it keep calling the value of false regarless if i change  < 1 to > 0 it goes the other way round and displays the image which should be shown in showpic3.php and doesn't show the noimage.png in showpic4.php the > number bit doesn't seem to be working or rather the if else isn't working?

Link to comment
Share on other sites

it keep calling the value of false regarless if i change  < 1 to > 0 it goes the other way round and displays the image which should be shown in showpic3.php and doesn't show the noimage.png in showpic4.php the > number bit doesn't seem to be working or rather the if else isn't working?

 

According to that statement, what is happening is there is that pic for showpic4. Check the data in the database for the ID you are passing.

 

I took the else out to avoid duplicate data, that should work like expected if there is no image returned by the SQL Query. But obviously there is data being returned by the SQL Query.

 

But I think I am understanding what you want to do.

 

<?php 
require("global/admin_functions.php"); 

if (isset($_GET['adid'])) {
    $query = "SELECT thumbnail3,thumbnailtype3 FROM zloads where intProductID=".$_GET['adid'];
    $result = mysql_query($query);
    if (mysql_num_rows($result) > 0) {
        $data = mysql_result($result,0,"thumbnail3"); 
        if (!empty($data) && $data != "") {
             $type = mysql_result($result,0,"thumbnailtype3"); 
             Header( "Content-type: $type");
             print $data; 
             exit;
        }
    }  
}

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

?>

 

Adding that if in there should test if that image has been set or not. Also you know you could consolidate this into 1 file instead of 4 or 5 different by doing this

 

<?php 
require("global/admin_functions.php"); 

$thumbnailNum = isset($_GET['type'])?$_GET['type']:1; // default to 1 if no value

if (isset($_GET['adid'])) {
    $query = "SELECT thumbnail" . $thumbnailNum . ",thumbnailtype" . $thumbnailNum . " FROM zloads where intProductID=".$_GET['adid'];
    $result = mysql_query($query);
    if (mysql_num_rows($result) > 0) {
        $data = mysql_result($result,0,"thumbnail" . $thumbnailNum); 
        if (!empty($data) && $data != "") {
             $type = mysql_result($result,0,"thumbnailtype" . $thumbnailNum); 
             Header( "Content-type: $type");
             print $data; 
             exit;
        }
    }  
}

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

?>

 

Then just add type=x where x is 1 2 3 4 etc....

 

Let me know how that works.

Link to comment
Share on other sites

Remove debug's after testing directly

 

<?php 
require("global/admin_functions.php"); 

if(!empty($_GET['adid']))
{
    $query = sprintf("SELECT thumbnail3,thumbnailtype3 FROM zloads where intProductID=%d",$_GET['adid']);
    $result = mysql_query($query) or die(mysql_error());
    if(mysql_num_rows($result) > 0)
    {
    	$img = mysql_fetch_assoc($result);
        $data = $img["thumbnail3"]; 
        $type = $img["thumbnailtype3"]; 
        die("FOUND: DATA type $type");//DEBUG
        header("Content-type: $type");
        print $data; 
        exit;
    }
    die("ERROR: No Records found"); //DEBUG
}
die("ERROR: adid not set"); //DEBUG
header("Content-Type: image/png"); 
echo readfile('../pix/noimage.png');
?>

 

 

 

But i think the SQL is probably wrong

try changing

$query = sprintf("SELECT thumbnail3,thumbnailtype3 FROM zloads where intProductID=%d",$_GET['adid']);

to

$query = sprintf("SELECT thumbnail3,thumbnailtype3 FROM zloads where ProductID=%d",$_GET['adid']);

Link to comment
Share on other sites

wow thanks for your help premiso it great I just successfully tried a few things and got it to work by using pretty much what you suggested earlier. I just removed the exit; and changed >0 to ==1

 

<? 
session_start();
error_reporting(7);
require("../global/admin_functions.php");


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

    }  
}

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


?>

 

does tht make any sense?

 

 

Link to comment
Share on other sites

No you need the exit.

 

Without the exit it will always execute the no-image portion also.

 

The whole point of the exit is so you can get rid of the else and if the script reaches the end of the page that means the correct conditions were not met.

 

You need the exit in there.

Link to comment
Share on other sites

mm i just put the exit; back in and it stopped working i took it out and it works again now!

 

Weird...

 

Well as long as it works I guess that is all you can ask for. I just figured it would throw a header error since you printed the data but yeah.

Link to comment
Share on other sites

works fine i guess with the ==1 the exit; always returns that value without it it gives it the option to read the next part works fine thanks for your help this has been very frustrating. I couldn't believe it when i was playing a round with it and it started working I had to check 4 it 5 times couldn't believe it. :)

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.