Iosys Posted March 19, 2011 Share Posted March 19, 2011 I'm wondering how to do this with javascript for a table that i have made in php and html. I want to hide the row for the table based on the value inside my first column for each row of the table. Like if column 1 has "apple" inside it, then the row would not be shown. I'm pretty sure this can be done in javascript but i'm not a coding guy, so any help would be appreciated! My table.php file that has the table i want to do this for: <script language="javascript"> imageX1='plus'; imageX2='plus'; imageX3='plus'; function toggleDisplay(e){ imgX="imagePM"+e; tableX="table"+e; imageX="imageX"+e; tableLink="tableHref"+e; imageXval=eval("imageX"+e); element = document.getElementById(tableX).style; if (element.display=='none') {element.display='block';} else {element.display='none';} if (imageXval=='plus') {document.getElementById(imgX).src='http://www.pvpstreams.com/icons/wowicon.png';eval("imageX"+e+"='minus';");document.getElementById(tableLink).title='Hide WoW';} else {document.getElementById(imgX).src='http://www.pvpstreams.com/icons/wowicon.png';eval("imageX"+e+"='plus';");document.getElementById(tableLink).title='Show WoW';} } </script> <?php $username="user"; $password="password"; $tmp="database"; mysql_connect(localhost,$username,$password); @mysql_select_db($tmp) or die( "Unable to select database"); $query="SELECT * FROM users"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table class="sortable" id="wow" border="1" cellpadding="0" cellspacing="0" style="margin-left:auto;margin-right:auto;text-align:left"> <tr> <th><font face="Arial, Helvetica, sans-serif">Game</font></th> <th><font face="Arial, Helvetica, sans-serif">Character</font></th> <th><font face="Arial, Helvetica, sans-serif">Rating</font></th> <th><font face="Arial, Helvetica, sans-serif"><img src="http://www.pvpstreams.com/table-images/xfirelogo.png"> Status</font></th> <th><font face="Arial, Helvetica, sans-serif"><img src="http://www.pvpstreams.com/table-images/xfirelogo.png"> Link</font></th> <th><font face="Arial, Helvetica, sans-serif">Realm</font></th> <th><font face="Arial, Helvetica, sans-serif"><img src="http://www.pvpstreams.com/table-images/livestreamlogo.png"> Status</font></th> <th><font face="Arial, Helvetica, sans-serif"><img src="http://www.pvpstreams.com/table-images/livestreamlogo.png"> Link</font></th> <th><font face="Arial, Helvetica, sans-serif">Team Setup</font></th> </tr> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"wowcharacter"); $f2=mysql_result($result,$i,"username"); $f3=mysql_result($result,$i,"livestream"); $f4=mysql_result($result,$i,"wowserver"); $f5=mysql_result($result,$i,"wowplayer1"); $f6=mysql_result($result,$i,"wowplayer2"); $f9=mysql_result($result,$i,"wowplayer3"); $f7=mysql_result($result,$i,"wowrealm"); $f8=mysql_result($result,$i,"xfire"); $f10=mysql_result($result,$i,"xfirecheck"); $f11=mysql_result($result,$i,"wowrating"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo "<center><img src=http://www.pvpstreams.com/table-images/wowtable.png>"; ?></center></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo "<a class=blue href=http://$f4.battle.net/wow/en/character/$f7/$f1/simple>$f1</a>"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f11; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo "$f10"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo "<a class=blue href=http://www.pvpstreams.com/xfire.php?user=$f2>$f8</a>"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f7; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php include("livestreamcheck.php"); ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo "<a class=blue href=http://www.pvpstreams.com/livestream.php?user=$f2>$f3</a>"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo "<img src=http://www.pvpstreams.com/wclassicons/$f5.png><img src=http://www.pvpstreams.com/wclassicons/$f6.png><img src=http://www.pvpstreams.com/wclassicons/$f9.png>" ?></font></td> </tr> <?php $i++; } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/231129-hide-table-row-based-on-column-value/ Share on other sites More sharing options...
Pikachu2000 Posted March 19, 2011 Share Posted March 19, 2011 Is there a particular reason you want to us JS for this? Quote Link to comment https://forums.phpfreaks.com/topic/231129-hide-table-row-based-on-column-value/#findComment-1189676 Share on other sites More sharing options...
Iosys Posted March 19, 2011 Author Share Posted March 19, 2011 No i just assume it can be done with javascript and I don't know if it's possible with anything else but if there is a better way i would love to hear about it. thanks for reply! Quote Link to comment https://forums.phpfreaks.com/topic/231129-hide-table-row-based-on-column-value/#findComment-1189680 Share on other sites More sharing options...
Pikachu2000 Posted March 19, 2011 Share Posted March 19, 2011 Well, I guess it depends on whether you just don't want to show it at all, or if you want to add a button or link to make it display when clicked . . . Quote Link to comment https://forums.phpfreaks.com/topic/231129-hide-table-row-based-on-column-value/#findComment-1189681 Share on other sites More sharing options...
Iosys Posted March 19, 2011 Author Share Posted March 19, 2011 No i don't want to add a button to be clicked to hide or display? I have reason for wanting row to hide if value in column is something Quote Link to comment https://forums.phpfreaks.com/topic/231129-hide-table-row-based-on-column-value/#findComment-1189708 Share on other sites More sharing options...
Pikachu2000 Posted March 19, 2011 Share Posted March 19, 2011 If that's the case, you can simply check the value in a conditional statement in php, and if it matches the value that you want to trigger the 'hide', just don't echo it. Hiding it with JS will still send it to the browser, and a user can easily find it in the html source, so doing this in php would make more sense for that reason also. Quote Link to comment https://forums.phpfreaks.com/topic/231129-hide-table-row-based-on-column-value/#findComment-1189712 Share on other sites More sharing options...
Iosys Posted March 19, 2011 Author Share Posted March 19, 2011 Thanks for the advice but how would I do that? I'm note sure how i would make it to not show certain row based on first value for that row? Quote Link to comment https://forums.phpfreaks.com/topic/231129-hide-table-row-based-on-column-value/#findComment-1189724 Share on other sites More sharing options...
floridaflatlander Posted March 19, 2011 Share Posted March 19, 2011 SQL and me don't get along but can you use it. Quote Link to comment https://forums.phpfreaks.com/topic/231129-hide-table-row-based-on-column-value/#findComment-1189728 Share on other sites More sharing options...
Pikachu2000 Posted March 20, 2011 Share Posted March 20, 2011 There are a couple of different ways you can do it. The best way would probably be to do it right in the query string by only SELECTing records that don't have the value you want not to be displayed. "SELECT * FROM table WHERE field != 'value'" Play with that a little bit and see if you can make something work. Post if you have problems or get stuck with anything. (Moving thread to PHP help) Quote Link to comment https://forums.phpfreaks.com/topic/231129-hide-table-row-based-on-column-value/#findComment-1189797 Share on other sites More sharing options...
Iosys Posted March 20, 2011 Author Share Posted March 20, 2011 Thanks Pickachu, that worked for what I wanted to do and wasn't that hard to implement. Quote Link to comment https://forums.phpfreaks.com/topic/231129-hide-table-row-based-on-column-value/#findComment-1190060 Share on other sites More sharing options...
Pikachu2000 Posted March 20, 2011 Share Posted March 20, 2011 Excellent. It's a better solution, too IMHO. Quote Link to comment https://forums.phpfreaks.com/topic/231129-hide-table-row-based-on-column-value/#findComment-1190070 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.