Jump to content

2 questions in 1 (math and images)


Rifts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.