0

hello. is that possible to hide an empty table when there is no records found from the mysql database. if possible, how? i have no idea to do it. hope anyone can help me. below is part of my coding:

<?php
                            $count=0;
                            include 'dbconnect.php';


                            if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) {

                            $startrow = 0;

                            } else {
                                $startrow = (int)$_GET['startrow'];
                                }

                                if (isset($_GET['serial_no']))
                                $serial_no = $_GET['serial_no'];

                                else
                                $serial_no = 0;

                                $query = "SELECT * FROM log where serial_no = '$serial_no'";
                                $result = mysql_query($query) or die('SQL error');

                                while($row = mysql_fetch_array($result, MYSQL_ASSOC))
                                {
                                ?>
                                    <TR>
                                        <td align="center" height="29"><font class="style3"><?php $count=$count+1; print($count);?></font></td>
                                        <TD><font class="style3">&nbsp;<?php echo $row['serial_no']; ?></font></TD>
                                        <TD><font class="style3">&nbsp;<?php echo $row['taken_date']; ?></font></TD>
                                        <TD><font class="style3">&nbsp;<?php echo $row['return_date']; ?></font></TD>
                                        <TD><font class="style3">&nbsp;<?php echo $row['person_incharged']; ?></font></TD>
                                        <TD><font class="style3">&nbsp;<?php echo $row['latest_action']; ?></font></TD>

                                    </TR>

                                    <?php
                                    }
                                        if($count< 1)
                                    {
                                        echo 'No records found';
                                    }
                                    ?>
3
Contributors
4
Replies
21
Views
2 Years
Discussion Span
Last Post by almostbob
0

You could do it programattically with PHP by changing some of your code around. It wouldn't be very hard to hide the table though with jQuery if it were empty, or contained a specific string.

Edited by pixelsoul

0

hi pixelsoul, thank you for your reply.

could you give me an example?

0

Example for using jQuery to hide the table after determining whether it had any content

$("table").each(function(){
    var count = $(this).children().length;
    if(count == 0){
        $(this).hide();
    }   
});

As long as there are no rows or any other elements inside of the table <table></table> it will be set to display:none;

0

<table> is currently outside this code scrap; it should not be
at line 22

if($result == nul) {echo '<table style="display:none;">';} else {echo '<table>';}

have not confirmed syntax, nul, empty, 0, "", depends on returned data format

jquery is a hell of an added burden to hide 1 element, server code reduces page size

Edited by almostbob

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.