html - Combine multiple table results into one table in php -
i followed web tutorial on how build basic search engine database problem when results displayed shows each result in own table on page? want merge results show under 1 table in html.
<?php include("dbconnect.php"); if(!isset($_post['search'])) { header("location:www.bacons.me"); } $search_sql="select * users username or firstname '%".$_post['search']."%'"; $search_query=mysql_query($search_sql); if(mysql_num_rows($search_query) !=0) { $search_rs=mysql_fetch_assoc($search_query); } ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="description" content="bacons.me"> <meta name="keywords" content="html,css,javascript"> <meta name="author" content="james narey"> <meta name=viewport content="width=device-width, initial-scale=1"> <link rel="icon" type="image/png" href="favicon-32x32.png" sizes="32x32" /> <link rel="icon" type="image/png" href="favicon-16x16.png" sizes="16x16" /> <link rel="stylesheet" type="text/css" href="main.css" > <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <title>bacons.me</title> </head> <body> <h1 class="logo"><a href="http://www.bacons.me/" class="logo- a">bacons.me</a></h1> <nav> <ul> <li><a href="http://www.bacons.me" class="nav-a">home</a></li> <li><a href="#" class="nav-a">about</a></li> <li><a href="search" class="nav-a">search</a></li> <li><a href="contact" class="nav-a">contact</a></li> </ul> <div class="handle">menu<span class="arrow"> ▾</span></div> </nav> <p>search results</p> <?php if(mysql_num_rows($search_query) !=0) { { ?> <table> <tr> <th>username</th> <th>first name</th> <th>surname</th> <th>shift</th> <th>agency</th> </tr> <tr> <td><?php echo $search_rs['username']; ?></td> <td><?php echo $search_rs['firstname']; ?></td> <td><?php echo $search_rs['lastname']; ?></td> <td><?php echo $search_rs['shift']; ?></td> <td><?php echo $search_rs['agency']; ?></td> </tr> <br> </table> <?php } while ($search_rs=mysql_fetch_assoc($search_query)); } else { echo "no results found"; } ?> <html> <title>results</title> <head> </head> <body> </body> </html> <footer> <p class="footer">website created james narey 2015.</p> </footer> </body> </html>}
...} while ($search_rs=mysql_fetch_assoc($search_query));
i suspect issue. you're creating table each time fetch next record. want this:
<table> <?php if(mysql_num_rows($search_query) !=0) { { ?> // fill in table... <?php } while ($search_rs=mysql_fetch_assoc($search_query)); ?> </table>
notice table tags outside loop, you'll create new row each record fetch
Comments
Post a Comment