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
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>';
?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.