premiso Posted December 27, 2008 Share Posted December 27, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/page/2/#findComment-724454 Share on other sites More sharing options...
shadiadiph Posted December 27, 2008 Author Share Posted December 27, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/page/2/#findComment-724465 Share on other sites More sharing options...
premiso Posted December 27, 2008 Share Posted December 27, 2008 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/page/2/#findComment-724468 Share on other sites More sharing options...
shadiadiph Posted December 27, 2008 Author Share Posted December 27, 2008 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/page/2/#findComment-724472 Share on other sites More sharing options...
premiso Posted December 27, 2008 Share Posted December 27, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/page/2/#findComment-724473 Share on other sites More sharing options...
shadiadiph Posted December 27, 2008 Author Share Posted December 27, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/page/2/#findComment-724475 Share on other sites More sharing options...
premiso Posted December 27, 2008 Share Posted December 27, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/page/2/#findComment-724477 Share on other sites More sharing options...
shadiadiph Posted December 27, 2008 Author Share Posted December 27, 2008 when i go to the direct url and put http://www.hmtcompany.com/user/showpic3.php?adid=149 http://www.hmtcompany.com/user/showpic4.php?adid=149 both pages are only displaying the noimage.png?? I just tried it using <?php echo $id; ?> and got the same result Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/page/2/#findComment-724478 Share on other sites More sharing options...
premiso Posted December 27, 2008 Share Posted December 27, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/page/2/#findComment-724480 Share on other sites More sharing options...
shadiadiph Posted December 27, 2008 Author Share Posted December 27, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/page/2/#findComment-724482 Share on other sites More sharing options...
shadiadiph Posted December 27, 2008 Author Share Posted December 27, 2008 i just noticed you took the else statement out of the equasion? Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/page/2/#findComment-724484 Share on other sites More sharing options...
premiso Posted December 27, 2008 Share Posted December 27, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/page/2/#findComment-724487 Share on other sites More sharing options...
MadTechie Posted December 27, 2008 Share Posted December 27, 2008 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']); Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/page/2/#findComment-724490 Share on other sites More sharing options...
shadiadiph Posted December 27, 2008 Author Share Posted December 27, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/page/2/#findComment-724492 Share on other sites More sharing options...
premiso Posted December 27, 2008 Share Posted December 27, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/page/2/#findComment-724495 Share on other sites More sharing options...
shadiadiph Posted December 27, 2008 Author Share Posted December 27, 2008 mm i just put the exit; back in and it stopped working i took it out and it works again now! Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/page/2/#findComment-724504 Share on other sites More sharing options...
premiso Posted December 27, 2008 Share Posted December 27, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/page/2/#findComment-724507 Share on other sites More sharing options...
shadiadiph Posted December 27, 2008 Author Share Posted December 27, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/138454-solved-only-showing-a-value-if-it-equals-something/page/2/#findComment-724515 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.