php - How to display multiple tables based on value -
i have inventory page displays information, i'm attempting have multiple tables based on department value, want display each department in tables rather single table, seems make page easier view, yes i'm new, yes i'm using mysql, know deprecated blah blah blah, local db , i'm self-taught. have use kind of loop or there easier way?
<?php $connect = mysql_connect("localhost", "me", "password") or die ("check connection."); mysql_select_db("radio"); $quey1="select * inventory order department, user"; $result=mysql_query($quey1) or die(mysql_error()); ?> <table border=1 cellpadding="10 cellspacing="1 style="background-color:#f0f8ff;" > <tr> <th>serial number</th> <th>model</th> <th>department</th> <th>user</th> <th>date</th> </tr> <?php while($row=mysql_fetch_array($result)){ echo "<tr><td>"; echo $row['serialnumber']; echo "</td><td>"; echo $row['model']; echo "</td><td>"; echo $row['department']; echo "</td><td>"; echo $row['user']; echo "</td><td>"; echo $row['date']; echo "</td></tr>"; } echo "</table>"; ?>
<?php $connect = mysql_connect("localhost", "me", "password") or die ("check connection."); mysql_select_db("radio"); $quey1="select * inventory order department, user"; $result=mysql_query($quey1) or die(mysql_error()); while($row=mysql_fetch_array($result)){ $resultsarr[] = $row; $departments[] = $row['department']; } foreach($departments $department) { ?> <table border=1 cellpadding="10 cellspacing="1 style="background-color:#f0f8ff;" > <tr> <th>serial number</th> <th>model</th> <th>department</th> <th>user</th> <th>date</th> </tr> <?php foreach($resultarr $value) if($value['department'] == $department) { ?> <tr> <td><?php echo $value['serialnumber']; ?></td> <td><?php echo $row['model']; ?></td> <td><?php echo $row['department']; ?></td> <td><?php echo $row['user']; ?></td> <td><?php echo $row['date']; ?></td> </tr> <?php } ?> <?php } ?>
try out , tell me if worked.
romeo onisim
Comments
Post a Comment