Can I do this?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
davidppppppppppp
Forum Newbie
Posts: 13
Joined: Mon Jul 03, 2006 9:31 pm

Can I do this?

Post by davidppppppppppp »

I have a MYSQL table with 11 entries id's (1 -11).

In my php script I have to use the Eval () on four of those eleven entries.

So I'm using this:

Code: Select all

if ($file == "1") { 

Eval ($content); 

} else { 

echo "$content"; 

}
This just repeats the content - one as it should be displayed and one as the code.

I need some way of doing this:

Code: Select all

$list = (1, 4, 6, ; // the id numbers that need to use Eval() 

if ($file == "$list") { 

Eval($content); 

} elseif ($file != "$list") { 

echo "$content"; 

}

Code: Select all

$list = (1, 4, 6, ;
This gets me errors. How can I define this list of numbers and use the elseif statement?

Thanks,
David
Last edited by davidppppppppppp on Mon Jul 03, 2006 10:01 pm, edited 4 times in total.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

use php tags, dude
davidppppppppppp
Forum Newbie
Posts: 13
Joined: Mon Jul 03, 2006 9:31 pm

Post by davidppppppppppp »

OK, I figured it out.

Code: Select all

if ($file == "1" || $file == "4" || $file == "6" || $file == "8") {

                  Eval($content);

          } else {

                  echo "$content";
 
                  }
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

davidppppppppppp wrote:OK, I figured it out.

Code: Select all

if ($file == "1" || $file == "4" || $file == "6" || $file == "8") {

                  Eval($content);

          } else {

                  echo "$content";
 
                  }

Code: Select all

$list = array (1, 4, 6, 8 );  // the id numbers that need to use Eval()

if (in_array($file,$list)) {

Eval($content);

} elseif ($file != "$list") {

echo "$content";

}
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

your elseif ($file != "$list") will always amount to true, as you are typecasting $list into a string, when it is an array.

also, it is eval(), not Eval().

:)
Post Reply