Php

Status
Not open for further replies.

murdocsvan

Web Programmer
Messages
896
Location
Surrey, UK
Hey, all i need to do is show all the information in an MySQL table in an HTML table, regardless of the number of rows. How would i code this?

Thanks in advance.
 
Okay here is my code:

PHP:
<?php

session_start();

//Check user is logged in in first place
if(!isset($_SESSION['user']))
	{
	header("location:******");
	}

//Stores mysql login details
$host="localhost"; // Host name 
$sql_username="*****"; // Mysql username 
$sql_password="*****"; // Mysql password 
$db_name="*****"; // Database name 
$tbl_name="admin"; // Table name 

//mysql Connect variable
$con = mysql_connect("$host","$sql_username","$sql_password");

//Query to retrieve information
$query = "SELECT * FROM admin";
$result = mysql_query($query,$con);

echo "<table border='1'>";
echo "<td><th>Username</th></tr>";
echo '<form action="user_delete.php" method="post">';
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array($result))
	{
	// Print out the contents of each row into a table
	echo "<tr><td>";
	echo $row['id'];
	echo "</td></tr>";
	echo "<tr><td>"; 
	echo $row['username'];
	echo "</td><td>";
	echo '<input type="button" value="" />';
	echo "</tr></td>";
	} 

echo "</form></table>";
?>

But for some reason it returns an error on the line:

PHP:
while($row = mysql_fetch_array($result))
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/vmrgjdq/public_html/test/users.php on line 29

Can anyone help?

Thanks.
 
PHP:
$result = mysql_query($query,$con);

Change this line to

PHP:
$result = mysql_query($query,$con) or die (mysql_error());

And post back the message.
 
It said "No Database selected", because i forgot to put in:

PHP:
//Database select
mysql_select_db($db_name, $con);

So i put it in and it works. Thanks a lot!
 
Status
Not open for further replies.
Back
Top Bottom