WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Displaying the records of table by giving user, password , database name and table name.
Categories : PHP, MySQL, Databases Update Picture
Raj shrestha
Date : Nov 22nd 2001
Grade : 4 of 5 (graded 4 times)
Viewed : 6048
File : disprecords.php
Images : No Images for this code example.
Search : More code by Raj shrestha
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?
/*************************************************************************
This file displays the content of a table. Only thing you have to do is to
give four parameter to the function, ie.  password, username, database name
and table name.

This program is written by Rajendra kumar shrestha and you are free to use
distribute and modify it. email rajensama@yahoo.com

If you want to see the demo , please send email so that i will put it in my web
site. www.rajensama.com

If you want the script for session and cookies which I have used for login
procedure in my web site you may send the email to me.
****************************************************************************/
function html_begin()
{
    print(
"<html>");
    print(
"<head>");
    print(
"<title>Print the table</title>");
    print(
"</head>");
    print(
"<body>");
}

function
html_end()
{
    print(
"</body>");
    print(
"</html>");
}

//here you have to define some variable

function printtable($user, $password,$dbase,$tablename)
{
     
html_begin();

       
//connect to database
                 
$dblink=mysql_pconnect("localhost",$user,$password) or
                         die(
"could not connect to server");

       
//connect to the database
                 
$db=mysql_select_db($dbase, $dblink) or
                         die(
"could not select the database");


           
$fieldresult=mysql_list_fields($user,$tablename,$dblink);



           
// first print the tag of the table
           
print("<table border='1'>\n");
           print(
"<tr>");

           
//extract the field name of the table
           
for($k=0; $k<mysql_num_fields($fieldresult); $k++)
                {
                print(
"<div align='center'>");
                print(
"<td>".mysql_field_name($fieldresult, $k)."</td>");
                print(
"</div>");
                }
           print(
"</tr>");

         
// $query="select * from mainnepal";
           
$query="select * from $tablename";
           
$result=mysql_query($query, $dblink);

           print(
"the number of result=".mysql_num_rows($result));


           for (
$i=0; $i<mysql_num_rows($result);$i++ )
                {

                print
"<tr>";
                for(
$k=0; $k<mysql_num_fields($fieldresult); $k++)
                {
                     print(
"<td>".mysql_result($result,$i,$k )."</td>" );
                }
                print(
"</tr>");
                }

           print(
"</table>");

html_end();
}

//declare some variable otherwise yu can simply pass the variable
$user="sa77bk";
$password="password";
$dbase="sa77bk";
$tablename="mainnepal";
//printtable($user, $password,$dbase,$tablename);
printtable($user, $password,$dbase,$tablename);

?>



This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server.
Categories : Databases, MySQL, Complete Programs, PHP, Databases
bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs.
Categories : Databases, PHP, MySQL, Complete Programs
phpAds, a complete banner and ad management system with detailled tracking and stats.
Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases
Point and Click Interface ala MS Access for creating SQL statements.
Categories : MySQL, Complete Programs, General SQL, PHP, Databases
Message of the Day - Random Message (Needs MySQL!)
Categories : Databases, HTML and PHP, PHP, MySQL
email new items in db
Categories : PHP, Email, Databases, MySQL, Beginner Guides
Alternating background color for HTML table rows
Categories : PHP, Databases, MySQL, HTML and PHP
color codes for positive and negative numbers
Categories : PHP, MySQL, Databases, HTML
Authorize Me! An authentication script.
Categories : MySQL, Databases, Authentication, PHP
A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL
Linked comboboxes with php-mysql & javascript
Categories : PHP, Java Script, Databases, MySQL
mysql_escape_string
Categories : PHP, MySQL, Databases, Strings
Automatically printing the contents of an sql table in MySQL.
Categories : MySQL, PHP, HTML and PHP, Databases
usercounter class
Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables
 Hans-Göran Puke wrote : 762
Tried this script, but got:
Warning: Supplied argument is not a valid MySQL result resource on line 55 and then further errors on line 74. Anyone who can explain why?
 
 raj shrestha wrote : 763
This is an working example. First of all you should have a table created and you should have some records. If you try to display without content , it might be problem. You should give the correct server name , password name,tablename.  Then it should definitely work. Because this program, I have tasted and put it here . I have not changed anythng except password and database name. 
 
 Michael Butler wrote :883
The issue is that in your example your $user and your $dbase are the same.. Where you have:
$fieldresult=mysql_list_fields($user,$tablename,$dblink); 

it should be:
$fieldresult=mysql_list_fields($dbase,$tablename,$dblink); 

Like I said, it works in your test and example because your database is the same as your username. This isn`t always the case..