gamerzfuse Posted August 13, 2009 Share Posted August 13, 2009 I tried what I thought would work, but it just messed things up and I seem to be unable to fit it in this statement. <tr onMouseover="this.style.backgroundColor='lightblue';" onMouseout="this.style.backgroundColor='transparent';" onclick="document.location='<?php echo $vehicles->ViewUrl() ?>'"; Where it says "<?php echo $vehicles->ViewUrl() ?>" I need an If.. Then statement asking for the variable "type", where it will use ViewUrl if the type is NOT Special, but if the type IS special, then it will use ViewUrl2. I tried, but it's failing all my ways. I'm sure I'm missing something obvious. I'm kinda looking for a quick answer and then I'll see how its done so I can adapt it to the other 20 places I need to perform similiar functions. Thanks in Advance! Quote Link to comment https://forums.phpfreaks.com/topic/170165-simple-if-then-statement/ Share on other sites More sharing options...
mikesta707 Posted August 13, 2009 Share Posted August 13, 2009 post the if statement that you have. its a simple process of if this echo this or if this echo this Quote Link to comment https://forums.phpfreaks.com/topic/170165-simple-if-then-statement/#findComment-897636 Share on other sites More sharing options...
icelandic Posted August 13, 2009 Share Posted August 13, 2009 <?php echo is_bool($type) ? $vehicles->ViewUrl() : $vehicles->ViewUrl2(); ?> This is shorthand way of an if then statement. I didn't know what you meant by "special" so I used the function "is_bool". That function can be substituted by a function defined by you. Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/170165-simple-if-then-statement/#findComment-897649 Share on other sites More sharing options...
KevinM1 Posted August 13, 2009 Share Posted August 13, 2009 <?php echo is_bool($type) ? $vehicles->ViewUrl() : $vehicles->ViewUrl2(); ?> This is shorthand way of an if then statement. I didn't know what you meant by "special" so I used the function "is_bool". That function can be substituted by a function defined by you. Hope this helps is_bool isn't really a good fit here as it only checks whether or not the value is a boolean, not if it's true or false. Also, if the OP's type is a string, it won't generate the desired result. To the OP, what is $type, and what's stored in it? Quote Link to comment https://forums.phpfreaks.com/topic/170165-simple-if-then-statement/#findComment-897655 Share on other sites More sharing options...
gamerzfuse Posted August 13, 2009 Author Share Posted August 13, 2009 <?php echo is_bool($type) ? $vehicles->ViewUrl() : $vehicles->ViewUrl2(); ?> This is shorthand way of an if then statement. I didn't know what you meant by "special" so I used the function "is_bool". That function can be substituted by a function defined by you. Hope this helps is_bool isn't really a good fit here as it only checks whether or not the value is a boolean, not if it's true or false. Also, if the OP's type is a string, it won't generate the desired result. To the OP, what is $type, and what's stored in it? $type = Car, SUV, Van, Truck or Special Basically I have a view.php page for all the vehicles, but Special is for trailer hitches, etc. I made a modified view.php file (spview.php) that only displays relevant information to the special items. This code is going to be my way of making sure that special links go to the special view.php page. I already setup a separate link to do so if you do it from the special category, but it's very makeshift: www.goodwillsusedcars.com/inventory.php (click the special tab and it changes to spinventory.php which has ViewUrl change to ViewUrl2, but it doesn't cover the fact that these special items come up under "All" also. Quote Link to comment https://forums.phpfreaks.com/topic/170165-simple-if-then-statement/#findComment-897699 Share on other sites More sharing options...
icelandic Posted August 14, 2009 Share Posted August 14, 2009 <?php $array = array('Car' => false, 'SUV' => false, 'Van' => false, 'Truck' => false. 'Special' => true); ?> ... <?php echo $array[$type] ? $vehicles->ViewUrl() : $vehicles->ViewUrl2(); ?> How about that? Quote Link to comment https://forums.phpfreaks.com/topic/170165-simple-if-then-statement/#findComment-898083 Share on other sites More sharing options...
gamerzfuse Posted August 14, 2009 Author Share Posted August 14, 2009 <?php $array = array('Car' => false, 'SUV' => false, 'Van' => false, 'Truck' => false. 'Special' => true); ?> ... <?php echo $array[$type] ? $vehicles->ViewUrl() : $vehicles->ViewUrl2(); ?> How about that? To be honest, I've never worked with arrays. I'll try and adapt that though.. it certainly looks functional. All the shorthand throws me off a bit, but I'll figure it out. Quote Link to comment https://forums.phpfreaks.com/topic/170165-simple-if-then-statement/#findComment-898208 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.