runnerjp Posted February 12, 2010 Share Posted February 12, 2010 How do i write this correctly....not sure where i have i gone wrong <?php echo '<tr $class = ($important == 1) ? 'mainrow1' : 'mainrow'; class="\$class"\> Link to comment https://forums.phpfreaks.com/topic/191869-quick-bit-of-php-code-needing-correcting/ Share on other sites More sharing options...
Deoctor Posted February 12, 2010 Share Posted February 12, 2010 i think u forgot to post the remaining code.. Link to comment https://forums.phpfreaks.com/topic/191869-quick-bit-of-php-code-needing-correcting/#findComment-1011323 Share on other sites More sharing options...
Mchl Posted February 12, 2010 Share Posted February 12, 2010 Your code doesn't make much sense I'm afraid... Something like this? <?php echo '<tr class = "'.(($important == 1) ? 'mainrow1' : 'mainrow'). '">'; ?> Link to comment https://forums.phpfreaks.com/topic/191869-quick-bit-of-php-code-needing-correcting/#findComment-1011324 Share on other sites More sharing options...
bugcoder Posted February 12, 2010 Share Posted February 12, 2010 try like this <?php $class = ($important == 1) ? 'mainrow1' : 'mainrow'; echo '<tr class="$class" >'; ?> Link to comment https://forums.phpfreaks.com/topic/191869-quick-bit-of-php-code-needing-correcting/#findComment-1011325 Share on other sites More sharing options...
runnerjp Posted February 12, 2010 Author Share Posted February 12, 2010 Your code doesn't make much sense I'm afraid... Something like this? <?php echo '<tr class = "'.(($important == 1) ? 'mainrow1' : 'mainrow'). '">'; ?> Worked great thanks.... its just to change colour of <td> dependant on whats selected in db ... thanks ! Link to comment https://forums.phpfreaks.com/topic/191869-quick-bit-of-php-code-needing-correcting/#findComment-1011326 Share on other sites More sharing options...
runnerjp Posted February 12, 2010 Author Share Posted February 12, 2010 Sorry about this but i was trying to use the rule above with this code but seems it dosent like it... <?php echo '<a href=\"index.php?page=message&forum=$forum;&id="'.$getthreads3['postid'].'"">"'.$getthreads3['title'].'"</a>?> Link to comment https://forums.phpfreaks.com/topic/191869-quick-bit-of-php-code-needing-correcting/#findComment-1011339 Share on other sites More sharing options...
jskywalker Posted February 12, 2010 Share Posted February 12, 2010 count the '"' (double quotes) Link to comment https://forums.phpfreaks.com/topic/191869-quick-bit-of-php-code-needing-correcting/#findComment-1011342 Share on other sites More sharing options...
Mchl Posted February 12, 2010 Share Posted February 12, 2010 If you want to expand variables in strings, you need to use double quotes. See this: $var = "Hello!"; echo 'Single quoted $var'; echo "Double quoted $var" ; and for arrays you need {} $arr = array('Hello!'); echo "Double quoted array {$arr[0]}"; Link to comment https://forums.phpfreaks.com/topic/191869-quick-bit-of-php-code-needing-correcting/#findComment-1011344 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.