Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. display query result in a table using PHP

display query result in a table using PHP

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
databasephphtmlmysqlquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PermissionDenied
    wrote on last edited by
    #1

    here's my code... this is intended to display a query result in a table but i am getting unwanted characters and no table was displayed... what could be wrong with my codes? here it is... thanks in advance.. <html> <body> <?php if (isset($_POST['btnSearch'])) { //connection to the database $connection = mysql_connect('localhost', 'root', ''); if (!$connection) die(mysql_error()); //select database if (!mysql_select_db('bbs', $connection)) die(mysql_error); $SearchOpt = $_POST['SearchOption']; if (empty($SearchOpt)) die("You did not select field."); $SearchKey = $_POST['txtKey']; if (empty($SearchKey)) die("You did not enter a keyword."); $sqlQuery = mysql_query("SELECT * FROM t_board WHERE $SearchOpt LIKE '%$SearchKey%' ORDER BY registerTime DESC;"); if(!$sqlQuery) die(mysql_error()); if (mysql_num_rows($sqlQuery)) { echo "<tbody>"; $recs = mysql_fetch_array($sqlQuery) or die(mysql_error()); foreach($recs as $rec) { echo "<tr>"; echo "<th>" . $rec['index'] . "</th>"; echo "<th>".$rec['subject']."</th>"; echo "<th>".$rec['writer']."</th>"; echo "<th>".$rec['registerTime']."</th>"; echo "</tr>"; } echo "</tbody>"; } } ?> </body> </html>

    J A 2 Replies Last reply
    0
    • P PermissionDenied

      here's my code... this is intended to display a query result in a table but i am getting unwanted characters and no table was displayed... what could be wrong with my codes? here it is... thanks in advance.. <html> <body> <?php if (isset($_POST['btnSearch'])) { //connection to the database $connection = mysql_connect('localhost', 'root', ''); if (!$connection) die(mysql_error()); //select database if (!mysql_select_db('bbs', $connection)) die(mysql_error); $SearchOpt = $_POST['SearchOption']; if (empty($SearchOpt)) die("You did not select field."); $SearchKey = $_POST['txtKey']; if (empty($SearchKey)) die("You did not enter a keyword."); $sqlQuery = mysql_query("SELECT * FROM t_board WHERE $SearchOpt LIKE '%$SearchKey%' ORDER BY registerTime DESC;"); if(!$sqlQuery) die(mysql_error()); if (mysql_num_rows($sqlQuery)) { echo "<tbody>"; $recs = mysql_fetch_array($sqlQuery) or die(mysql_error()); foreach($recs as $rec) { echo "<tr>"; echo "<th>" . $rec['index'] . "</th>"; echo "<th>".$rec['subject']."</th>"; echo "<th>".$rec['writer']."</th>"; echo "<th>".$rec['registerTime']."</th>"; echo "</tr>"; } echo "</tbody>"; } } ?> </body> </html>

      J Offline
      J Offline
      Jules VDV
      wrote on last edited by
      #2

      You might want to try changing this: $sqlQuery = mysql_query("SELECT * FROM t_board WHERE $SearchOpt LIKE '%$SearchKey%' ORDER BY registerTime DESC;"); to this: $sqlQuery = mysql_query("SELECT * FROM t_board WHERE $SearchOpt LIKE '%" . $SearchKey . "%' ORDER BY registerTime DESC;"); Also, make sure your request is POSTing the correct parameters: How many records exist in $recs after you run the query? Try print count($recs);

      Greenridge Business Systems

      1 Reply Last reply
      0
      • P PermissionDenied

        here's my code... this is intended to display a query result in a table but i am getting unwanted characters and no table was displayed... what could be wrong with my codes? here it is... thanks in advance.. <html> <body> <?php if (isset($_POST['btnSearch'])) { //connection to the database $connection = mysql_connect('localhost', 'root', ''); if (!$connection) die(mysql_error()); //select database if (!mysql_select_db('bbs', $connection)) die(mysql_error); $SearchOpt = $_POST['SearchOption']; if (empty($SearchOpt)) die("You did not select field."); $SearchKey = $_POST['txtKey']; if (empty($SearchKey)) die("You did not enter a keyword."); $sqlQuery = mysql_query("SELECT * FROM t_board WHERE $SearchOpt LIKE '%$SearchKey%' ORDER BY registerTime DESC;"); if(!$sqlQuery) die(mysql_error()); if (mysql_num_rows($sqlQuery)) { echo "<tbody>"; $recs = mysql_fetch_array($sqlQuery) or die(mysql_error()); foreach($recs as $rec) { echo "<tr>"; echo "<th>" . $rec['index'] . "</th>"; echo "<th>".$rec['subject']."</th>"; echo "<th>".$rec['writer']."</th>"; echo "<th>".$rec['registerTime']."</th>"; echo "</tr>"; } echo "</tbody>"; } } ?> </body> </html>

        A Offline
        A Offline
        Al42
        wrote on last edited by
        #3
        1. Did I miss the and

        tags?

        1. is used inside a . For data inside you should be using
        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups