Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/170165-simple-if-then-statement/
Share on other sites

<?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

<?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?

<?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.

<?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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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