Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/231129-hide-table-row-based-on-column-value/
Share on other sites

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.

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)

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.