php - Trying to display SQL data in html table -
so have file supposed run sql query , return data , populate html table reason not returning data, in sql in database query return data not on website.
<?php //run query $sql = "select id, topic_id, name, surveyid, questionid, longdesc, text, first_name , last_name , email polling_results 'topic_id' = '147796' order 'id, displayorder'"; $result = mysql_query($sql); //fetch results while ($row = mysql_fetch_array($result)) { //display results echo '<br /><table class="table table-bordered table-condensed">'; echo '<thead><tr>'; echo '<th>name</th>'; echo '<th>email</th>'; echo '<th>question text</th>'; echo '<th>answer</th>'; echo '</tr></thead>'; echo '<tbody><tr>'; echo "<td>".$row['first_name']."</td>"; echo "<td>".$row['email']."</td>"; echo "<td>".$row['longdesc']."</td>"; echo "<td>".$row['text']."</td>"; echo '</tr></tbody></table>'; } ?>
got working, thank guys/gals.
you need change code below : because of mysql_* deprecated php 5.6 , onwards should use mysqli_* .
create db connection follows :
<?php // create connection $db_conn = mysqli_connect ( $servername, $username, $password, $dbname ); // check connection if (! $db_conn) { die ( "connection failed: " . mysqli_connect_error () ); } ?>
and code :
<?php //run query $sql = "select id, topic_id, name, surveyid, questionid, longdesc, text, first_name , last_name , email polling_results 'topic_id' = '147796' order 'id, displayorder'"; $result = mysqli_query($db_conn,$sql); // creating table format echo '<br /><table class="table table-bordered table-condensed">'; echo '<thead><tr>'; echo '<th>name</th>'; echo '<th>email</th>'; echo '<th>question text</th>'; echo '<th>answer</th>'; echo '</tr></thead>'; echo '<tbody>'; //fetch results while ($row = mysqli_fetch_array($result,mysqli_assoc)) { //display results <tr>'; echo "<td>".$row['first_name']."</td>"; echo "<td>".$row['email']."</td>"; echo "<td>".$row['longdesc']."</td>"; echo "<td>".$row['text']."</td>"; echo '</tr>'; } echo '</tbody></table>'; // display data end. ?>
if issue face please let me know.
Comments
Post a Comment