|
|
|
|
|
|
| |
| <?
/*************************************************************************
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..
| |
|
|
|