Jump to content

Display table of my entries from MySQL


tinkertron

Recommended Posts

As mention before, i'm new to the whole PHP programming, but can some tell me how to display my db from MySQL to the web? I know you need to call the db up from MySQL, but how is it display to the web page as a table like excel? I have about 17 colms and there is going to be at least 600+ rows. Someone start me off so I can start learning.

Link to comment
https://forums.phpfreaks.com/topic/186767-display-table-of-my-entries-from-mysql/
Share on other sites

Try this:

<?php
include '../incl/incl.php'; // Link to your database connection
$sql = mysql_query("SELECT * FROM `questions`");
echo '<table>';
echo '<tr>';
while($field = mysql_fetch_field($sql)){
echo '<th>'.ucfirst($field->name).'</th>';
}
echo '</tr>';
while($row = mysql_fetch_assoc($sql)){
echo '<tr>';
foreach($row as $item){
	echo '<td style="padding-right:50px;border:solid 1px #000;">'.htmlentities(substr($item, 0, 30)).'</td>';
}
echo '</tr>';
}
echo '</table>';
?>

I tried Russell code first and this is what I got:

 

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\display.php on line 9

 

here's the code:

<?php

$con = mysql_connect("localhost","username","password");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

$q = mysql_query("SELECT * FROM test");

while ($row = mysql_fetch_assoc($q)) {

  print_r($row);

}

 

 

mysql_close($con);

?> 

 

Would this be because it does know what database or table to pull from?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.