Jump to content

Recommended Posts

Hello,
i been trying to make the following script work, and i been having some difficulty cause it's acting weird
here'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
Link to comment
https://forums.phpfreaks.com/topic/32935-if-else-help/
Share on other sites

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. 
Link to comment
https://forums.phpfreaks.com/topic/32935-if-else-help/#findComment-153364
Share on other sites

ok thanks for the reply first,
here is the whole thing

i 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.
Link to comment
https://forums.phpfreaks.com/topic/32935-if-else-help/#findComment-153512
Share on other sites

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]
<?php
if ($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 $
Link to comment
https://forums.phpfreaks.com/topic/32935-if-else-help/#findComment-153637
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.