Reply to topic
php & MySQL
john barrett


Joined: 04 Nov 2005
Posts: 41
Location: Hawaii
Reply with quote
Hi,
I am trying to display a DB table using php and MySQL.
I am able to connect to MySQL, and the Database, but the table will not display.
Can anybody please help me?
I have the form at:
http://johnbarrett.net/MySQL.php
tells me the connection is good, but the DB table will not display Crying or Very sad


{I have stripped the login information, DB stuff, and table name}
Code:

<?php
// Connecting, selecting database
$link = mysql_connect('***', '**', '**')
   or die('Could not connect: ' . mysql_error());
echo 'Connected successfully to MySQL<br>';

mysql_select_db('**') or die('Could not select database');
echo 'Connected successfully to php database<br>';

// Performing SQL query
$query = 'SELECT * FROM MyDB_Table';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result)) {
   
   echo "\t</tr>\n";
}

echo "</table>\n";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);
?>
Connie


Joined: 26 Mar 2005
Posts: 176
Location: The Internet
Reply with quote
Here is some code I used recently:
Code:

<?php

/* Building MYSQL connection */
$link = mysql_connect("server","username","password") or die("Cannot

connect");
mysql_select_db("your_db") or die("Cannot select db");

/* Sending query to MYSQL */
$query= "select * from my_table";
$result= mysql_query($query) or die("Query failed");

/* Printing results in HTML */
print "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    print "\t<tr>\n";
    foreach ($line as $col_value) {
    print "\t\t<td>$col_value</td>\n";
  }
  print "\t</tr>\n";
}
print "</table>\n";

/* Free resultset */
mysql_free_result($result);

/* Closing connection */
mysql_close($link);

?>
john barrett


Joined: 04 Nov 2005
Posts: 41
Location: Hawaii
Reply with quote
Hi Connie,
Thanks so much Very Happy
This is exactly what I was trying to do!
Your my hero!

This worked to do what I wanted:
http://johnbarrett.net/MySQL.php

Just a quiz for my Nutrition teacher.
I will play with this to get it not to display certain information, but baby steps this is great:)

Thanks for your help Smile
php & MySQL
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic