Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 05-13-2009, 08:39 AM   #1 (permalink)
murdocsvan's Avatar
 
Ultra Techie

Join Date: Jun 2007

Location: Surrey, UK

Posts: 849

murdocsvan is on a distinguished road

Default Php

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.
__________________

murdocsvan is offline  
Old 05-13-2009, 01:19 PM   #3 (permalink)
murdocsvan's Avatar
 
Ultra Techie

Join Date: Jun 2007

Location: Surrey, UK

Posts: 849

murdocsvan is on a distinguished road

Default Re: Php

Okay here is my code:

PHP Code:
<?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 Code:
while($row mysql_fetch_array($result)) 
Quote:
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.
__________________


Last edited by murdocsvan; 05-13-2009 at 01:23 PM.
murdocsvan is offline  
Old 05-13-2009, 01:36 PM   #4 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: Php

PHP Code:
$result mysql_query($query,$con); 
Change this line to

PHP Code:
$result mysql_query($query,$con) or die (mysql_error()); 
And post back the message.
__________________

Need website help? PM me!
CrazeD is offline  
Old 05-13-2009, 01:57 PM   #5 (permalink)
murdocsvan's Avatar
 
Ultra Techie

Join Date: Jun 2007

Location: Surrey, UK

Posts: 849

murdocsvan is on a distinguished road

Default Re: Php

It said "No Database selected", because i forgot to put in:

PHP Code:
//Database select
mysql_select_db($db_name$con); 
So i put it in and it works. Thanks a lot!
__________________

murdocsvan is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
A Guide to Installing Apache, PHP, MySQL, and PHPMyAdmin on Windows CrazeD Programming Discussions 17 06-17-2009 04:27 PM
How echo works in PHP Osiris Programming Discussions 0 03-04-2009 08:34 AM
PHP - what it does and what it doesn’t Osiris Programming Discussions 1 02-16-2009 04:09 PM
Wev Development: How does PHP work? Osiris Programming Discussions 1 01-08-2009 04:31 PM
Removing PHP For Increased Download Speed Rex100 Programming Discussions 4 07-21-2008 03:49 PM