WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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 : List all values in selected fields from selected tables from selected database
Categories : PHP, MySQL, Databases, HTML and PHP Click here to Update Your Picture
Michel Beeckmans
Date : Feb 23rd 2001
Grade : 3 of 5 (graded 4 times)
Viewed : 7399
File : mysql_list.zip
Images : No Images for this code example.
Search : More code by Michel Beeckmans
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

1. Select a database from the combo box
2. Select the fields you want to see from the tables
3. Click on selected fields to see all records matching your selection

Code :

<?php
// lines to change to make your connection
$DB_SERVER="localhost"; // Database Server machine
$DB_LOGIN="ODBC@localhost"; // Database login
$DB_PASSWORD=""; // Database password
$HTTP_HOST="localhost"; // HTTP Host
$DOCROOT="list_mysql"; // Path, where application is installed
$DB="";
set_magic_quotes_runtime(0); // Disable magic_quotes_runtime - don't change
$ocon = mysql_connect("localhost",$DB_LOGIN,$DB_PASSWORD);

//mysql error function

function mysql_die($mess)
{
echo "Mysql-Error " . mysql_error() ."<br>";
echo $mess . "<br>";
exit;
}

if(isset($rtn_db))
{
$DB=$rtn_db;
unset($rtn_db);
}

// have we changed the database

if(isset($do_db))
{
unset($do_db);
$DB=$dbs;
}

// have we selected to sow the details

if((isset($do_all)) || (isset($do_sel)))
{
?>
<html><head>
</head><body><center>
<?php
$DB=$the_db;
echo $DB;
$rest=mysql_list_tables($DB);
$tables=array();
mysql_data_seek($rest,0);
$nb_tbl=0;
while ($rowt=mysql_fetch_array($rest))
{
$sql="show fields from $rowt[0]";
$resf["$rowt[0]"]=mysql_db_query($DB,$sql) or mysql_die($sql);
$row_max=mysql_num_rows($resf["$rowt[0]"]);
$j=0;
for($i=0; $i<$row_max; $i++)
{
$key=$rowt[0].$i;
if(($$key=="on") || (isset($do_all)))
{
$tables["$rowt[0]"][$j]=$key;
$j++;
}
}
if($j!=0) $nb_tbl++;
}
unset($do_all);
unset($do_sel);
mysql_data_seek($rest,0);
echo "<center><table width=100% border=2><tr>";
if ($nb_tbl!=0) $tblw=(int)(100/$nb_tbl);
while ($rowt=mysql_fetch_array($rest))
{
if(isset($tables["$rowt[0]"][0]))
{
echo "<td align=center width=\"$tblw%\" ><A Href=\"#$rowt[0]\">$rowt[0]
</A></td>";
}
}
echo "</tr></table></center>";
mysql_data_seek($rest,0);
while ($rowt=mysql_fetch_array($rest))
{
if(isset($tables["$rowt[0]"][0]))
{
echo "<center><table><tr>";
echo "<td><A id=\"$rowt[0]\"></A>Table: " . $rowt[0] ."</td>";
echo "</tr></table></center>";
echo "<center><table border=1><tr>";

$sql="show fields from $rowt[0]";
$resr=mysql_db_query($DB,$sql) or mysql_die($sql);
$sql="SELECT";
for($i=0; $i<999; $i++)
{
if(isset($tables["$rowt[0]"][$i]))
{
$val=str_replace($rowt[0],"",$tables["$rowt[0]"][$i]);
mysql_data_seek($resr,(int)($val));
$rowr=mysql_fetch_array($resr);
echo "<td>Field: " . $rowr[0] . "</td>";
if ($sql>"SELECT") $sql.=",";
$sql.= " " . $rowr[0] ;
}
else continue;
}
$sql.= " from " . $rowt[0];
$res = mysql_db_query($DB,$sql) or mysql_die($sql);
echo "</tr>";
$nb_field = mysql_num_fields($res);
while ($rowd=mysql_fetch_array($res))
{
echo "<tr>";
for($k=0; $k<$nb_field; $k++)
{
$val=$rowd[$k] . "";
echo "<td>" . $val . "</td>";
}
echo "</tr>";
}
echo "</table></center>";
echo "<hr size=2>";
}
}
mysql_data_seek($rest,0);
echo "<center><table border=2 width=100%><tr>";
while ($rowt=mysql_fetch_array($rest))
{
if(isset($tables["$rowt[0]"][0]))
{
echo "<td align=center width=\"$tblw%\" ><A Href=\"#$rowt[0]\">$rowt[0]
</A></td>";
}
}
?>
</tr></table><br>
<form><input type=hidden name="rtn_db" value="<?echo $DB;?>">
<input type=submit name="back" value=back>
</form></center>

<center><font face=verdana size=2 color=navy>
<li>Written by <A href="mailto:michel@afixis.com">michel beeckmans</A>
from <A href="http://www.afixis.com">Afixis Trade Unlimited</A></center>
</font>
</body></html>
<?php
exit;
}
?>

<html><head></head><body>
<script language="JavaScript">
<!--
function do_check( chk_name,chk_nb,chk_val)
{
for(i=0; i<chk_nb; i++)
{
chk_el=chk_name+i;
document.forms(1).elements(chk_el).checked=chk_val;
}
return false;
}

//-->
</script>
<center>
<table width=50% border=1><form method="POST">
<font face="verdana,helvetica,arial" size="1">
<tr><td align=center>Select your database</td></tr>
<tr><td align=center>
<select size=1 name="dbs">
<?php
$i= ($DB<=""?0:1);
if ($DB>"") $rest=mysql_list_tables($DB);
$dbs=mysql_list_dbs();
while ($rowdb=mysql_fetch_array($dbs))
{
echo "<option value=$rowdb[0]";
if ($i==0 || $DB==$rowdb[0])
{
echo " SELECTED";
$i++;
if ($DB<="")
{
$DB=$rowdb[0]; // Database containing the tables
$rest=mysql_list_tables($DB);
}
}
echo ">$rowdb[0]</option>";
}
?>
</select></td></tr>
<tr><td align=center>
<input type=submit value="Change database" name="do_db">
</td></tr></form></font>
</table><hr size=2 color=fuschia>

<table width=25% border=1>
<font face="verdana,helvetica,arial" size="2">
<tr><td align=center><?echo $DB;?> tables</td></tr>
<?php
$max_col=mysql_num_rows($rest);
$colsize=(int)(100/$max_col);
?>
</font>
</table><br>

<form method="POST">
<table width=100% border=1>
<font face="verdana,helvetica,arial" size="1">
<tr>
<?php
while ($rowt=mysql_fetch_array($rest))
{
echo "<td align=center width=$colsize% colspan=2>$rowt[0]</td>";
}
mysql_data_seek($rest,0);
echo "</tr>";
$row_max=0;
while ($rowt=mysql_fetch_array($rest))
{
$sql="show fields from $rowt[0]";
$resf["$rowt[0]"]=mysql_db_query($DB,$sql) or mysql_die($sql);
if(mysql_num_rows($resf["$rowt[0]"])>$row_max)
$row_max=mysql_num_rows($resf["$rowt[0]"]);
}

for($i=0; $i<$row_max; $i++)
{
echo "<tr>";
mysql_data_seek($rest,0);
while ($rowt=mysql_fetch_array($rest))
{
if($i<mysql_num_rows($resf["$rowt[0]"]))
{
mysql_data_seek($resf["$rowt[0]"],$i);
$val=mysql_fetch_array($resf["$rowt[0]"]);
echo "<td>" . $val[0] . "</td><td>";
echo "<input type=checkbox name=$rowt[0]$i>";
echo "</td>";
}
else
{
echo "<td colspan=2></td>";
}
}
echo "</tr>";
}
mysql_data_seek($rest,0);
echo "<tr>";
while ($rowt=mysql_fetch_array($rest))
{
echo "<td colspan=2 align=center >";
$rn = $rowt[0];
$rv = mysql_num_rows($resf["$rowt[0]"]);
?>
<input type=submit value=" All "
onClick="return do_check('<? echo $rn;?>',<? echo $rv;?>,1)">
<input type=submit value=" None "
onClick="return do_check('<? echo $rn;?>',<? echo $rv;?>,0)">
<?php
echo "</td>";
}
?>
<tr><td align=center colspan=<?echo ($max_col * 2);?>>
<b>Select the fields you want to see</b>
</td></tr>
<tr><td colspan=<?echo ($max_col);?> align=center>
<input type=hidden name="the_db" value="<?echo $DB; ?>">
<input type=submit name="do_all" value="Show all"></td>
<td colspan=<?echo ($max_col);?> align=center>
<input type=submit name="do_sel" value="Show selected fields">
</td></tr>
</font></table>
</form>
<center><font face=verdana size=2 color=navy>
<li>Written by <A href="mailto:michel@afixis.com">michel beeckmans</A>
from <A href="http://www.afixis.com">Afixis Trade Unlimited</A></center>
</font>
</body></html>




Complex paging with no resultset limit
Categories : PHP, MySQL, Databases, Output Control, HTML and PHP
phpFormGenerator for Dynamic Form Generation from MySQL
Categories : PHP, PHP Classes, MySQL, Databases, HTML and PHP
Editing the virtusertable and sendmail.cw via PHP3.0 and Mysql
Categories : MySQL, HTML and PHP, PHP, Databases
This function will populate the options in a drop down HTML select list in a form from a database query.
Categories : MySQL, General SQL, PHP, HTML and PHP, Databases
Message of the Day - Random Message (Needs MySQL!)
Categories : Databases, HTML and PHP, PHP, MySQL
Required form fields that pull from MySQL database
Categories : PHP, HTML and PHP, Databases, MySQL
This program will take data from a user via a web based form, validate it, show it to the user for re-validation, and finally insert it into the database. Plenty of sanity checking on the fields in the form.
Categories : MySQL, HTML and PHP, PHP, Complete Programs, Databases
mySQL/PHP/search with multientry form and table output with colored rows
Categories : PHP, Beginner Guides, MySQL, HTML and PHP, Databases
Automatically printing the contents of an sql table in MySQL.
Categories : MySQL, PHP, HTML and PHP, Databases
bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
How can i Preload a 'SELECT MULTIPLE'?
Categories : HTML and PHP, PHP, MySQL, Databases
Creating thumbnails from MySQL Blobs online
Categories : PHP, MySQL, Graphics, HTML and PHP, Databases
Storing / Retrieving pictures from database This can be used for banner / ads exchange. very useful for people developing big portal with ads in the site........
Categories : PHP, MySQL, Databases, HTML and PHP
Database resultset navigation
Categories : PHP, HTML and PHP, Databases, MySQL, Navigation
Alternating background color for HTML table rows
Categories : PHP, Databases, MySQL, HTML and PHP
  william babigumira wrote :582
Cool script, ... if it allowed me to edit my database at the same time, that would be even more cool.

Thanks man