Jump to content

Recommended Posts

Hey two things first how can I write if statements like this:

 

if $total = 5 or 6

  do this

 

if $total = 10 or 11 or 12

  do this

 

if $total = 13 or 14 or 15

  do this

 

etc

 

and secondly how do I display an image using php assuming its name is image.png and its in the same directory as my php file?

 

 

thanks!

Link to comment
https://forums.phpfreaks.com/topic/205903-2-questions-in-1-math-and-images/
Share on other sites

Hey two things first how can I write if statements like this:

 

if $total = 5 or 6

  do this

 

if $total = 10 or 11 or 12

  do this

 

if $total = 13 or 14 or 15

  do this

 

if($total => 5 && =<6)
{
    do this
}
elseif($total => 10 && =<12)
{
    do this
}
elseif($total => 13 && =<15
{
    do this
}

 

As for the second part?

 

I'm not sure, where are you retrieving the file path for the image from? a database? or are you typing it yourself?

 

usually you would do:

<img href="<?php echo "/directory/image.png" ?>" />

BTW, this syntax

<?php

if($total => 5 && =<6)
{
    do this
}
elseif($total => 10 && =<12)
{
    do this
}
elseif($total => 13 && =<15
{
    do this
}
?>

is completely invalid. If I were doing this, I would use a switch statement:

<?php
switch ($total) {
   case 5:
   case 6:
              echo '$total is 5 or 6';
              break;
   case 10:
   case 11:
   case 12:
              echo '$total is either 10, 11, or 12';
              break;
   case 13:
   case 14:
   case 15:
             echo '$total is either 13, 14, or 15';
             break;
}
?>

 

Ken

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.