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';
                                    }
                                    ?>

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.

hi pixelsoul, thank you for your reply.

could you give me an example?

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;

<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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.