Jump to content

[SOLVED] Conditions inside variables.


unkwntech

Recommended Posts

Its been a while since I've done it or seen it for that matter and I cant seem to come up with the correct syntax, what I need is a condition inside a variable assignment something like this:

$page['text']='<table width="100%" border="0" cellpadding="2">' . "\n<tr>
<td width=\"7%\"><a href=\"&s=" . if($sort==0){echo 1;}else{echo 0;} . "\">ID</a></td>
<td width=\"19%\"><a href=\"&s=" . if($sort==2){echo 3;}else{echo 2;} . "\">Name</td>

Link to comment
https://forums.phpfreaks.com/topic/121901-solved-conditions-inside-variables/
Share on other sites

use a ternary operator

 

$page['text']='<table width="100%" border="0" cellpadding="2">' . "\n<tr>
<td width=\"7%\"><a href=\"&s=" . (($sort==0) ? 1 : 0 ). "\">ID</a></td>
<td width=\"19%\"><a href=\"&s=" . (($sort==2) ? 3 : 2 ) . "\">Name</td>

Archived

This topic is now archived and is closed to further replies.

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