PDA

View Full Version : What's wrong with this code?



-Adam
05-11-2009, 09:49 PM
}if ($arr['rankpos'] == "1" || $arr['rankpos'] == "2" ||$arr['rankpos'] == "3" ||$arr['rankpos'] == "4" ||$arr['rankpos'] == "5" ||$arr['rankpos'] == "6" ||$arr['rankpos'] == "7" ||$arr['rankpos'] == "8" ||$arr['rankpos'] == "9" ||$arr['rankpos'] == "10" ||$arr['rankpos'] == "11"){ ?>
<table align="center" width="100%" class="tbl">
<tr><td align="center" class="hdr">.::Unlucky::.</td></tr>
<tr><td align="left" class="tbl">
GOO Away.<br />
</td></tr>
</table>
<br />

Whats wrong with this? Im trying to make it so that if your rankpos isnt at least 12, it says go away.

jackass
05-11-2009, 09:52 PM
Why don't you just do... :S


| $arr['rankpos'] >= "12" |

eLv
06-11-2009, 03:12 AM
OR


<?php if ($arr['rankpos'] != "12") {
<table align="center" width="100%" class="tbl">
<tr><td align="center" class="hdr">.::Unlucky::.</td></tr>
<tr><td align="left" class="tbl">
GOO Away.<br />
</td></tr>
</table>
<br />
<?php } ?>

Jamesy
06-11-2009, 09:26 AM
OR


<?php if ($arr['rankpos'] != "12") {
<table align="center" width="100%" class="tbl">
<tr><td align="center" class="hdr">.::Unlucky::.</td></tr>
<tr><td align="left" class="tbl">
GOO Away.<br />
</td></tr>
</table>
<br />
<?php } ?>

That wont do what he wants if the rank is above 12 though :)

ThisNameWillDo!
06-11-2009, 10:03 AM
<?
if ($arr['rankpos'] >= "12")
echo "Go away?";
?>

Source
06-11-2009, 02:36 PM
I don't quite get why people are putting integers in strings?



<?php

if( $arr['rankpos'] < 12 ) echo 'Go Away!';

?>


Also I am pretty sure everyone has been using the equal to or more than operator, when he clearly stated he wanted it to show go away if the level wasn't at least 12.

Blob
06-11-2009, 07:45 PM
I don't quite get why people are putting integers in strings?



<?php

if( $arr['rankpos'] < 12 ) echo 'Go Away!';

?>


Also I am pretty sure everyone has been using the equal to or more than operator, when he clearly stated he wanted it to show go away if the level wasn't at least 12.

No need for if there, you could easily do




<?php

echo ( $arr['rankpos'] < 12 ) ? "Go Away": "Hello";

?>


Where hello is the content

Source
07-11-2009, 02:53 PM
That is really extremely illogical blob, apart from the fact you may have wanted to show off you can do some extremely basic PHP work.

Those statements ( : ? ) should only be used for setting variables in my personal opinion as what you have done would look messy and unorganised if it was a big amount of content. He wanted a simple if, else statement that would do it neatly and without the need to over complicate things.

Blob
07-11-2009, 03:09 PM
That is really extremely illogical blob, apart from the fact you may have wanted to show off you can do some extremely basic PHP work.

Those statements ( : ? ) should only be used for setting variables in my personal opinion as what you have done would look messy and unorganised if it was a big amount of content. He wanted a simple if, else statement that would do it neatly and without the need to over complicate things.

Not really, I was showing a different way to do things, that doesn't look messy at all...

Invent
07-11-2009, 04:15 PM
Not really, I was showing a different way to do things, that doesn't look messy at all...

If you've got a huge block of HTML in the echo then the ternary operator is not a smart choice.

Blob
07-11-2009, 04:29 PM
If you've got a huge block of HTML in the echo then the ternary operator is not a smart choice.

True, but I thought this was only to say Go Away, not to display other things aswell.

Dentafrice
07-11-2009, 05:47 PM
True, but I thought this was only to say Go Away, not to display other things aswell.
No you didn't.

You knew it was going to say other things.. I mean how couldn't you of? You specifically explained that "hello" was where the content was going to go.

Why would he have a page that checked to see if they were a certain level, and nothing else? I mean of course he is going to display content for those users > 12..

Blob
07-11-2009, 08:19 PM
No you didn't.

You knew it was going to say other things.. I mean how couldn't you of? You specifically explained that "hello" was where the content was going to go.

Why would he have a page that checked to see if they were a certain level, and nothing else? I mean of course he is going to display content for those users > 12..

Yes, given the option of content after, I wasn't to know he wanted to put heaps of content in. Could have easily just put "" where hello is to display nothing.

Want to hide these adverts? Register an account for free!