How to display HTML data from database?

How to display contents of database in html table..?

  • i want contents of my database to be displayed in html table.... how to insert dis code in php file..?? <?php //Connecting to MySQL Database $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } //Select Database mysql_select_db("dictionary", $con); //MySQL Query: SELECT $sql="SELECT * FROM dictionary.list WHERE word like '&#3231%'"; $result=mysql_query($sql,$con); //while($row = mysql_fetch_array($result)){ //echo "<td>" . $row['word'] . "</td>"; //echo "<td>" . $row['word'] . "</td> "</tr>"; //echo "</table>"; while($row = mysql_fetch_array($result)){ //echo $row['word'] . "</br>"; $curr_word=$row['word']; echo '<a href="http://localhost/dr.php/?selword='... '">' .$curr_word.'</a>'; echo "<br/>"; } //Terminating MySQL Connection mysql_close($con); ?> i want dis href link inside table.... n that table shoul contain 5 columns n 5 rows.... can anyone please help me out in dis....??? :( thank you.... :)

  • Answer:

    // printing table headers collum names dont not have to be included in which case // remove this area from here #### for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo "<td>{$field->name}</td>"; } echo "</tr>"; // remove this area to here #### // print table rows $row is an array of each rows data while($row = mysql_fetch_row($result)) { // here we assign each row[index] to $cell one at a time and print it intoi the table td cell foreach($row as $cell){ if ($cell==$row['word']) { echo '<a href="http://localhost/dr.php/?selword='... '">' .$curr_word.'</a>'; }else{ echo "<td>$cell</td>"; } } } echo "</tr>\n"; // in the end we dont need the number of rows as each is printed untill the end of the database // the select statment filters the data by only getting the rows we want using WHERE

Swathi at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

// printing table headers collum names dont not have to be included in which case // remove this area from here #### for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo "<td>{$field->name}</td>"; } echo "</tr>"; // remove this area to here #### // print table rows $row is an array of each rows data while($row = mysql_fetch_row($result)) { // here we assign each row[index] to $cell one at a time and print it intoi the table td cell foreach($row as $cell){ if ($cell==$row['word']) { echo '<a href="http://localhost/dr.php/?selword='… '">' .$curr_word.'</a>'; }else{ echo "<td>$cell</td>"; } } } echo "</tr>\n"; // in the end we dont need the number of rows as each is printed untill the end of the database // the select statment filters the data by only getting the rows we want using WHERE

Mark O

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.