runnerjp Posted May 30, 2008 Share Posted May 30, 2008 hey guys i wanna chnage the background of the table with an if statement like so <tr <?php if($important == 1){bgcolor='#993399'} else {bgcolor='#F2F2F2'} ?> class='mainrow'><td width="3%"> but it does not seem to work .. Link to comment https://forums.phpfreaks.com/topic/107968-solved-chnaging-background-if-if-statement/ Share on other sites More sharing options...
ILYAS415 Posted May 30, 2008 Share Posted May 30, 2008 try... <tr <?php if($important == 1){ echo "bgcolor='#993399'"; } else { echo "bgcolor='#F2F2F2'"; } ?> class='mainrow'><td width="3%"> that should definately work Link to comment https://forums.phpfreaks.com/topic/107968-solved-chnaging-background-if-if-statement/#findComment-553355 Share on other sites More sharing options...
runnerjp Posted May 30, 2008 Author Share Posted May 30, 2008 humm my $imprtant is not working...can you see where its going wrong?? $getthreads="Select * from forumtutorial_posts where parentid='0' and forum = '$forum' ORDER BY lastrepliedto DESC $max"; $getthreads2=mysql_query($getthreads) or die("Could not get threads"); while($getthreads3=mysql_fetch_array($getthreads2)) { $getthreads3[title]=strip_tags($getthreads3[title]); $getthreads3[author]=strip_tags($getthreads3[author]); $important=$getthreads3[important] ?> <tr <?php if($important == 1){ echo "bgcolor='#993399'"; } else { echo "bgcolor='#F2F2F2'"; } ?>class='mainrow'><td width="3%"><? if($getthreads3[author] == $puser){ ?> <img src="http://www.runningprofiles.com/images/my folder.gif" alt="My" /> <?} else { echo 'nooo'; } ?> Link to comment https://forums.phpfreaks.com/topic/107968-solved-chnaging-background-if-if-statement/#findComment-553362 Share on other sites More sharing options...
ILYAS415 Posted May 30, 2008 Share Posted May 30, 2008 instead of... $important=$getthreads3[important] try using... $important=$getthreads3['important']; As you can see i aded a semi colon to the end of the variable and also added those small quotes around important Link to comment https://forums.phpfreaks.com/topic/107968-solved-chnaging-background-if-if-statement/#findComment-553402 Share on other sites More sharing options...
runnerjp Posted May 30, 2008 Author Share Posted May 30, 2008 saldy that did not work in chnaging the colour buti can echo the no 0 or 1! <?php $getthreads="Select * from forumtutorial_posts where parentid='0' and forum = '$forum' ORDER BY lastrepliedto DESC $max"; $getthreads2=mysql_query($getthreads) or die("Could not get threads"); while($getthreads3=mysql_fetch_array($getthreads2)) { $getthreads3[title]=strip_tags($getthreads3[title]); $getthreads3[author]=strip_tags($getthreads3[author]); $getthreads3[important]=strip_tags($getthreads3[important]); $important=$getthreads3['important']; ?> <tr <?php if($important == 1){ echo "bgcolor='#993399'"; } else { echo "bgcolor='#F2F2F2'"; } ?>class='mainrow'><td width="3%"><? if($getthreads3[author] == $puser){ ?> Link to comment https://forums.phpfreaks.com/topic/107968-solved-chnaging-background-if-if-statement/#findComment-553404 Share on other sites More sharing options...
runnerjp Posted May 30, 2008 Author Share Posted May 30, 2008 i was thinkin of doing something like this instead <?php if($important == 1){ class='mainrow1' } else {class='mainrow2} ?> how wouldi do this correctly Link to comment https://forums.phpfreaks.com/topic/107968-solved-chnaging-background-if-if-statement/#findComment-553410 Share on other sites More sharing options...
darkfreaks Posted May 30, 2008 Share Posted May 30, 2008 if($important == 1){ class='mainrow1' } else if($important==2) {class='mainrow2} Link to comment https://forums.phpfreaks.com/topic/107968-solved-chnaging-background-if-if-statement/#findComment-553414 Share on other sites More sharing options...
runnerjp Posted May 30, 2008 Author Share Posted May 30, 2008 with <?php if($important == 1){ class='mainrow1' } else if($important == 2) {class='mainrow2}?> i get unexpected =expecting t_sting Link to comment https://forums.phpfreaks.com/topic/107968-solved-chnaging-background-if-if-statement/#findComment-553418 Share on other sites More sharing options...
darkfreaks Posted May 30, 2008 Share Posted May 30, 2008 if($important == 1){ class='mainrow1' } else if($important==0) {class='mainrow2} Link to comment https://forums.phpfreaks.com/topic/107968-solved-chnaging-background-if-if-statement/#findComment-553423 Share on other sites More sharing options...
runnerjp Posted May 30, 2008 Author Share Posted May 30, 2008 i think its how class='mainrow1' is done Link to comment https://forums.phpfreaks.com/topic/107968-solved-chnaging-background-if-if-statement/#findComment-553425 Share on other sites More sharing options...
darkfreaks Posted May 30, 2008 Share Posted May 30, 2008 shouldnt ie be a variable like $class ??? Link to comment https://forums.phpfreaks.com/topic/107968-solved-chnaging-background-if-if-statement/#findComment-553426 Share on other sites More sharing options...
runnerjp Posted May 30, 2008 Author Share Posted May 30, 2008 huh what u mean,,, class is css Link to comment https://forums.phpfreaks.com/topic/107968-solved-chnaging-background-if-if-statement/#findComment-553433 Share on other sites More sharing options...
ILYAS415 Posted May 30, 2008 Share Posted May 30, 2008 your ,meant to be echoing the class Link to comment https://forums.phpfreaks.com/topic/107968-solved-chnaging-background-if-if-statement/#findComment-553495 Share on other sites More sharing options...
runnerjp Posted May 30, 2008 Author Share Posted May 30, 2008 if($important==1) { $class = "mainrow1"; } else { $class = "mainrow2"; } then <tag class="' . $class . '"> did it wahoo Link to comment https://forums.phpfreaks.com/topic/107968-solved-chnaging-background-if-if-statement/#findComment-553503 Share on other sites More sharing options...
Sulman Posted May 30, 2008 Share Posted May 30, 2008 You need to echo the class <?php <tr class="<?php if($important == 1){ echo "mainrow1"; } else { echo "mainrow2"; } ?>"><td width="3%"> ?> Link to comment https://forums.phpfreaks.com/topic/107968-solved-chnaging-background-if-if-statement/#findComment-553507 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.