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 'ಟ%'"; $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
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:
- How to Display Products in a table format?Best solution by Stack Overflow
- How to display HTML table with angularJS?Best solution by Stack Overflow
- How do I create an HTML table, in jQuery, with JSON data?Best solution by Stack Overflow
- How to Display Woocommerce products in Table Format?Best solution by WordPress
- How do you write specific data to an HTML table?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.