xcoffeesx Posted January 5, 2007 Share Posted January 5, 2007 Hello,i been trying to make the following script work, and i been having some difficulty cause it's acting weirdhere's the script<?php if ($IMG_WIDTH < 750) { (include "/pathname/file1.htm");}else {(include "/pathname/file2.htm");}?>$IMG_WIDTH is a constant which is given by uploading a picture, so to keep the layout of the website the same no matter the width i create 2 files for the headers and footers to load in 2 conditions if the image is smaller or bigger than 750.now the script is only reading the if part and not the else part when i put the parameter of <, and when i put the == the script works fine.can anyone help in this ?thanks for your time in advance Quote Link to comment https://forums.phpfreaks.com/topic/32935-if-else-help/ Share on other sites More sharing options...
.josh Posted January 5, 2007 Share Posted January 5, 2007 first off, are you sure you mean that $IMG_WIDTH is a constant? because constants do not have $ signs in front of them. If that doesn't work...If the else is not executing, then $IMG_WIDTH is obviously less than 750. But this might not necessarily mean that the width is say, 700. if $IMG_WIDTH is not set or doesn't exist, then it will read as 0 < 750. Quote Link to comment https://forums.phpfreaks.com/topic/32935-if-else-help/#findComment-153364 Share on other sites More sharing options...
xcoffeesx Posted January 5, 2007 Author Share Posted January 5, 2007 ok thanks for the reply first,here is the whole thingi am creating a user send your picture as ecard thing, the user goes to the site upload their picture, then be able to send it to family and friends etc, boring i know but it has a small twist to it.so when the user uploads the picture or image that's where the $IMG_WIDTH goes in, then the script takes you to a bunch of templates to put up the card together, so the $IMG_WIDTH is a value which is variable once you uploaded, in the file1.htm and file2.htm i set 2 values for the table width of the page one of them is a fixed 750 the other is width={IMG_WIDTH}.now the script if/else is working on the == 750 the else works fine on the < it just doesn't read the else.i just tried a small thing which i put a small echo"img=$IMG_WIDTH" on top of the page and it's reading the img width fine just the ELSE statement is not working in the < less than.Thanks for your time. Quote Link to comment https://forums.phpfreaks.com/topic/32935-if-else-help/#findComment-153512 Share on other sites More sharing options...
.josh Posted January 5, 2007 Share Posted January 5, 2007 okay so you did [code]echo "img=$IMG_WIDTH";[/code]and it printed out the width. That means it's not a constant, but a regular variable. And your if/else statement then looks like this:[code]<?phpif ($IMG_WIDTH < 750) { (include "/pathname/file1.htm");} else { (include "/pathname/file2.htm");}?>[/code]according to your code, it should work. Now, you mentioned [code]width={IMG_WIDTH}[/code]in this instance, IMG_WIDTH is being used as if it were a constant, not a regular variable. somewhere in your script do you have like[code]define('IMG_WIDTH', $IMG_WIDTH); [/code]because if you don't, you either need to add that so that your use of the constant will work, or else, change it from using a constant to a regular variable with the $ Quote Link to comment https://forums.phpfreaks.com/topic/32935-if-else-help/#findComment-153637 Share on other sites More sharing options...
xcoffeesx Posted January 5, 2007 Author Share Posted January 5, 2007 exactly, i added the define, still the same what's weird is the when the == is put the script works fine and reads the else, when i change to < it just stops.Thanks for helping i will try and figure it out ??? Quote Link to comment https://forums.phpfreaks.com/topic/32935-if-else-help/#findComment-153736 Share on other sites More sharing options...
Carterhost Posted January 5, 2007 Share Posted January 5, 2007 What happens if you change it to:[code]if ($IMG_WIDTH <= 750) { [/code] Quote Link to comment https://forums.phpfreaks.com/topic/32935-if-else-help/#findComment-153760 Share on other sites More sharing options...
xcoffeesx Posted January 5, 2007 Author Share Posted January 5, 2007 the else won't work either !!! it's driving my nuts actually Quote Link to comment https://forums.phpfreaks.com/topic/32935-if-else-help/#findComment-153779 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.