shadiadiph Posted December 26, 2008 Share Posted December 26, 2008 Is this possible on my display page I have this code <td> <img src="showpic2.php?adid=<?=$id?>" /> </td> the default background is in css and has a no picture image which shows when a picture is not there but for example in this table td there is the no image background picture controlled by css but no picture in the database in this cell so how can i make it so it only shows a picture when there is a value to the picture? right now just shows the background with the annoying no image x. ??? Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/ Share on other sites More sharing options...
Mchl Posted December 26, 2008 Share Posted December 26, 2008 <td> <?php if (!empty($id)) { ?> <img src="showpic2.php?adid=<?php echo $id; ?>" /> <?php } ?> </td> Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-723915 Share on other sites More sharing options...
shadiadiph Posted December 26, 2008 Author Share Posted December 26, 2008 mm thanks i get the idea behimd this but $id will always have a value as this page is asking showpic.php to get the picture value based on the $id Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-723917 Share on other sites More sharing options...
Mchl Posted December 26, 2008 Share Posted December 26, 2008 So when is the picture not supposed to show up? Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-723919 Share on other sites More sharing options...
shadiadiph Posted December 26, 2008 Author Share Posted December 26, 2008 if the showpic.php isn't producing any value right now with what you gave me if there is a picture it shows the picture and if there isn't a picture it shows a red cross where a picture should be. Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-723923 Share on other sites More sharing options...
Mchl Posted December 26, 2008 Share Posted December 26, 2008 You need to know beforehand, if showpic.php will return a picture or not. Alternative approach would be, to modify showpic.php so that it will return a 1x1 transparent picture, when no actual picture is created. Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-723926 Share on other sites More sharing options...
shadiadiph Posted December 26, 2008 Author Share Posted December 26, 2008 mm sorry i have no idea how to do that? <?php require("../global/admin_functions.php"); $query = "SELECT thumbnail1,thumbnailtype1 FROM zloads where intProductID=".$_GET['adid']; $result = MYSQL_QUERY($query); $data = MYSQL_RESULT($result,0,"thumbnail1"); $type = MYSQL_RESULT($result,0,"thumbnailtype1"); Header( "Content-type: $type"); print $data; ?> Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-723930 Share on other sites More sharing options...
Mchl Posted December 26, 2008 Share Posted December 26, 2008 <?php require("../global/admin_functions.php"); $query = "SELECT thumbnail1,thumbnailtype1 FROM zloads where intProductID=".$_GET['adid']; $result = mysql_query($query); if (mysql_num_rows() > 0) { $data = mysql_result($result,0,"thumbnail1"); $type = mysql_result($result,0,"thumbnailtype1"); Header( "Content-type: $type"); print $data; } else { //picture was not found in database //display 'empty' picture //it would be best just to load it from external file } ?> Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-723940 Share on other sites More sharing options...
shadiadiph Posted December 26, 2008 Author Share Posted December 26, 2008 mm sorry but that doesn't work doesn't diplay a picture even when there is one now Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-723947 Share on other sites More sharing options...
Mchl Posted December 26, 2008 Share Posted December 26, 2008 Sorry if (mysql_num_rows() > 0) { should be if (mysql_num_rows($result) > 0) { Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-723953 Share on other sites More sharing options...
shadiadiph Posted December 26, 2008 Author Share Posted December 26, 2008 thanks that works but still showing an image guess i will have to reprogram it to upload a blank gif i will let you know if it works. Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-723958 Share on other sites More sharing options...
Mchl Posted December 26, 2008 Share Posted December 26, 2008 Since I only added comments, it sure does not display an image I left the actual coding to you Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-723959 Share on other sites More sharing options...
shadiadiph Posted December 27, 2008 Author Share Posted December 27, 2008 mm this script isn't actually working if their is apictur it still displays it but if there isn't it wont display anything in the else { section when i view the page directly showpic it gives me the error Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hmtcompa/public_html/user/showpic3.php on line 6 if their is no image won't show anything even something simple. <?php require("../global/admin_functions.php"); $query = "SELECT thumbnail4,thumbnailtype4 FROM zloads where intProductID=".$_GET['adid']; $result = mysql_query($query); if (mysql_num_rows($result) > 0) { $data = mysql_result($result,0,"thumbnail4"); $type = mysql_result($result,0,"thumbnailtype4"); Header( "Content-type: $type"); print $data; } else { print hello; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-724316 Share on other sites More sharing options...
shadiadiph Posted December 27, 2008 Author Share Posted December 27, 2008 I have this no it is outputting a load if rubbish looks like it is trying to read the .png file but displays aload of binary code? <?php require("../global/admin_functions.php"); $query = "SELECT thumbnail4,thumbnailtype4 FROM zloads where intProductID=".$_GET['adid']; $result = mysql_query($query); if (mysql_num_rows($result) > 0) { $data = mysql_result($result,0,"thumbnail4"); $type = mysql_result($result,0,"thumbnailtype4"); Header( "Content-type: $type"); print $data; } else { header("Content-Type: image/png"); $file = ('../pix/noimage.png'); $source = (fread(fopen($file, "r"), filesize($file))); print ($source); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-724324 Share on other sites More sharing options...
shadiadiph Posted December 27, 2008 Author Share Posted December 27, 2008 i got rid of the num_rows error i was gettting it now displays the noimage.png all the time even when there is a piture in the database and never displays the value of $data??? <?php require("global/admin_functions.php"); $query = "SELECT thumbnail2,thumbnailtype2 FROM zloads where intProductID=".$_GET['adid']; $result = mysql_query($query); if (mysql_query($result) > 0) { $data = mysql_result($result,0,"thumbnail2"); $type = mysql_result($result,0,"thumbnailtype2"); Header( "Content-type: $type"); print $data; } else { header("Content-Type: image/png"); $file = ('../pix/noimage.png'); $source = (fread(fopen($file, "r"), filesize($file))); print ($source); }?> Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-724398 Share on other sites More sharing options...
RussellReal Posted December 27, 2008 Share Posted December 27, 2008 <?php require("../global/admin_functions.php"); $query = "SELECT thumbnail4,thumbnailtype4 FROM zloads where intProductID=".$_GET['adid']." LIMIT 1"; $result = mysql_query($query); if ($r = mysql_fetch_assoc($result)) { $data = $r["thumbnail4"]; $type = $r["thumbnailtype4"]; header( "Content-type: $type"); print $data; } else { header("Content-Type: image/png"); $source = file_get_contents("../pix/noimage.png"); print $source; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-724407 Share on other sites More sharing options...
shadiadiph Posted December 27, 2008 Author Share Posted December 27, 2008 mm thanks but that doesn't work gives the error Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/hmtcompa/public_html/user/showpic4.php on line 6 this is the closest i have come with no errors but the problem is in the > 0 part of it. <?php require("../global/admin_functions.php"); $query = "SELECT thumbnail3,thumbnailtype3 FROM zloads where intProductID=".$_GET['adid']; $result = mysql_query($query); if (mysql_query($result) > 0) { $data = mysql_result($result,0,"thumbnail3"); $type = mysql_result($result,0,"thumbnailtype3"); Header( "Content-type: $type"); print $data; } else { header("Content-Type: image/png"); $file = ('../pix/noimage.png'); $source = (fread(fopen($file, "r"), filesize($file))); print ($source); }?> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-724409 Share on other sites More sharing options...
RussellReal Posted December 27, 2008 Share Posted December 27, 2008 <?php require("../global/admin_functions.php"); $query = "SELECT `thumbnail4`,`thumbnailtype4` FROM `zloads` WHERE `intProductID` = '{$_GET['adid']}' LIMIT 1"; $result = mysql_query($query); if ($r = mysql_fetch_assoc($result)) { $data = $r["thumbnail4"]; $type = $r["thumbnailtype4"]; header( "Content-type: $type"); print $data; } else { header("Content-Type: image/png"); $source = file_get_contents("../pix/noimage.png"); print $source; } ?> ok bro.. try that.. and try both EXISTING images.. and NONEXISTING images.. if anything it will show the warning for non existing images.. Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-724412 Share on other sites More sharing options...
shadiadiph Posted December 27, 2008 Author Share Posted December 27, 2008 thanks yours only works on the one where there are images in the database it is like in my code > 0 shows the noimage.png always and not the image in the database where there is one and if it its < 1 it shows the image in the database but where there are no images it doesn't display the noimage.png Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-724415 Share on other sites More sharing options...
RussellReal Posted December 27, 2008 Share Posted December 27, 2008 <?php require("../global/admin_functions.php"); $query = "SELECT `thumbnail4`,`thumbnailtype4` FROM `zloads` WHERE `intProductID` = '{$_GET['adid']}' LIMIT 1"; $result = mysql_query($query); if ($r = @mysql_fetch_assoc($result)) { $data = $r["thumbnail4"]; $type = $r["thumbnailtype4"]; header( "Content-type: $type"); print $data; } else { header("Content-Type: image/png"); $source = file_get_contents("../pix/noimage.png"); print $source; } ?> ok in this case, the above will solve ur problem Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-724416 Share on other sites More sharing options...
shadiadiph Posted December 27, 2008 Author Share Posted December 27, 2008 freaky got the same result the blank image wasn't showing again but when i checked the direct result on showpic3.php and showpic4.php the result was showing the noimage.png both times but on the page that is calling it was showing the image correctly that was in the database being called by showpic3.php but when i viewed showpic3.php it was displaying only the noimage.png and on showpic4.php the same showed the image but on the display page calling showpic4.php it just came up blank?? Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-724422 Share on other sites More sharing options...
shadiadiph Posted December 27, 2008 Author Share Posted December 27, 2008 main page <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> showpic3.php <?php require("../global/admin_functions.php"); $query = "SELECT `thumbnail3`,`thumbnailtype3` FROM `zloads` WHERE `intProductID` = '{$_GET['adid']}' LIMIT 1"; $result = mysql_query($query); if ($r = @mysql_fetch_assoc($result)) { $data = $r["thumbnail3"]; $type = $r["thumbnailtype3"]; header( "Content-type: $type"); print $data; } else { header("Content-Type: image/png"); $source = file_get_contents("../pix/noimage.png"); print $source; } ?> showpic4.php <?php require("../global/admin_functions.php"); $query = "SELECT `thumbnail4`,`thumbnailtype4` FROM `zloads` WHERE `intProductID` = '{$_GET['adid']}' LIMIT 1"; $result = mysql_query($query); if ($r = @mysql_fetch_assoc($result)) { $data = $r["thumbnail4"]; $type = $r["thumbnailtype4"]; header( "Content-type: $type"); print $data; } else { header("Content-Type: image/png"); $source = file_get_contents("../pix/noimage.png"); print $source; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-724424 Share on other sites More sharing options...
shadiadiph Posted December 27, 2008 Author Share Posted December 27, 2008 this is doing my head in doesn't seem capable of calling the else statement properly. if the code says if (mysql_query($result) < 1) { it shows the image from the database everytime if the code says if (mysql_query($result) > 1) { it shows the noimage,png everytime always one but not either or? full code is <?php require("global/admin_functions.php"); $query = "SELECT thumbnail3,thumbnailtype3 FROM zloads where intProductID=".$_GET['adid']; $result = mysql_query($query); if (mysql_query($result) < 1) { $data = mysql_result($result,0,"thumbnail3"); $type = mysql_result($result,0,"thumbnailtype3"); Header( "Content-type: $type"); print $data; } else { header("Content-Type: image/png"); $file = ('../pix/noimage.png'); $source = (fread(fopen($file, "r"), filesize($file))); print ($source); }?> if it is set at <0 or >0 it shows the noimage.png everytime. Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-724425 Share on other sites More sharing options...
hobeau Posted December 27, 2008 Share Posted December 27, 2008 Hi shadiadiph, I believe the confusion is being caused by checking 'mysql_query($result)' instead of checking 'mysql_num_rows($result)'. 'mysql_query' returns a boolean value of true if the query executes successfully or false if it doesn't. In this case you are trying to run a query on a result so the function returns false. As you know, PHP is a loosely typed language, so when you are comparing a boolean value against an integer, PHP will get the integer value of the boolean which in this case ends up being 0 (false == 0,, but false !== 0). so: if (mysql_query($result) < 1) { always returns true and runs the code in the first set of brackets if (mysql_query($result) > 1) { always returns false and runs the code in the else set of brackets therefore always showing the noimage.png. Hope this helps! Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-724439 Share on other sites More sharing options...
shadiadiph Posted December 27, 2008 Author Share Posted December 27, 2008 i tried this earlier if you look up the post i used if (mysql_num_rows($result) <0) { and it kept producing an error Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hmtcompa/public_html/user/showpic3.php on line 6 Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/#findComment-724448 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.