Web Hosting Talk







View Full Version : PHP Echo help


Mark_W
01-14-2008, 12:38 AM
Hello
I'm trying to get certain ads to show up in certain categories but don't know where to go from here.

here is the code i have already

<?
if ($category ==666) echo display_ad(15,$base_url);
else echo display_ad(2,$base_url);?>


where the
if ($category ==666

how do i add more than one category
example
if ($category ==666==123==1234
any help is really appreciated

fastdeploy
01-14-2008, 12:44 AM
how do i add more than one category
example
if ($category ==666==123==1234
any help is really appreciated

That syntax makes no sense to me.

$category == 666 || $category == 123 || $category == 1234

doesn't work?

Mark_W
01-14-2008, 12:46 AM
that was just a example im trying to get the code to read more than one category

Mark_W
01-14-2008, 01:22 AM
never mind i got it
alls i had to do was repeat the step
like this

old code

<?
if ($category ==666) echo display_ad(15,$base_url);
else echo display_ad(2,$base_url);?>


new code

<?
if ($category ==666) echo display_ad(17,$base_url);
if ($category ==24) echo display_ad(17,$base_url);
else echo display_ad(4,$base_url);?>

foobic
01-14-2008, 01:31 AM
Ugh. If you want a cleaner option take a look at the in_array (http://au2.php.net/manual/en/function.in-array.php) function. Beware of using it with a lot of values though - it's said to be inefficient.

CyberAlien
01-14-2008, 05:13 AM
<?
if ($category ==666) echo display_ad(17,$base_url);
if ($category ==24) echo display_ad(17,$base_url);
else echo display_ad(4,$base_url);?>

You've got a small typo: it should be elseif before ($category ==24), otherwise display_ad(4, $base_url) will be executed in category 666 too.

So fixed code:
<?
if ($category == 666) echo display_ad(17,$base_url);
elseif ($category == 24) echo display_ad(17,$base_url);
else echo display_ad(4,$base_url);?>

Jonaid
01-14-2008, 08:10 AM
wouldn't a swtich function be better here?


$category= "666";

switch ($category){
case "666":
echo display_ad(17,$base_url);
break;

case "24":
echo display_ad(17,$base_url);
break;

default:
echo display_ad(4,$base_url);



Try it...

azizny
01-14-2008, 08:14 AM
switch($category){
case 666;case 24;//as many cases as you need here
echo display_ad(17,$base_url);
break;
default:
echo display_ad(4,$base_url);
}


Peace,

Jonaid
01-14-2008, 08:17 AM
It seems great minds think alike azizny :)

sasha
01-14-2008, 08:48 AM
$default_ad = '4' ;
$ads = array (
'666' => '17',
'24' => '17',
'11' => '6'// , .. etc
);

display_ad( (($ads[$category]) ? $ads[$category] : $default_ad) ,$base_url) ;

azizny
01-14-2008, 11:49 AM
It seems great minds think alike azizny :)

Sorry... With the Ajax thing on, I am not able to see who posted before me before I viewed the page.

Peace,

Mark_W
01-14-2008, 02:42 PM
Thanks All for your wonderful help

I think I'm gonna try going with this code


switch($category){
case 666;case 24;//as many cases as you need here
echo display_ad(17,$base_url);
break;
default:
echo display_ad(4,$base_url);
}

ill let you know how it goes

Mark_W
01-14-2008, 05:19 PM
OK this worked out great here is what i used


<?
switch($category){
case 666;case 24;case 25;case 200;case 103;
case 27;case 18;case 23;case 16;case 201;//as many cases as you need here
echo display_ad(17,$base_url);
break;
default:
echo display_ad(4,$base_url);
}
?>


hope this topic helps others as much as it help me.
Once again thanks to everybody for taking your time to help..:agree: