|
|
|
| Title : |
Retrieve text from table and email to your e-
address in pipe delimited format. |
| Categories : |
PHP, MySQL |
 Paulus de |
| Date : |
May 16th 1999 |
| Grade : |
1 of 5 (graded 3 times) |
| Viewed : |
6919 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by Paulus de |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
<HTML>
<BODY>
<TITLE> Retrieve table Data </TITLE>
<?
require("admin_retrieve.php3");
/*
You can either put the following files in an "admin_retrieve.php3" file,
or
just put your variables right down below (don't forget to "unquote").
Both work.
$hostname = "";
$username = "";
$password = "";
$dbName = "";
$userstable = ""; // MySQL table to retrieve data from
$email = "your@email.address"; // the site administrator's email
address
*/
require ("toptext.txt"); // you can delete this, it is just for my own format
$mysql = MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database");
@mysql_select_db( "$dbName") or die( "Unable to select database");
$fields = mysql_list_fields($dbName, $userstable);
$num = mysql_num_fields($fields);
/*===============================================*/
/* */
/* Form submitted, gather result from query */
/* */
/*===============================================*/
if ($do_query != "") {
$do_show = 0;
$do_value = 0;
$query = "SELECT ";
for ($i = 0 ; $i < $num ; $i++) {
if ($show[$i] == "on") {
if ($do_show != 0) {
$query .= ", ";
}
$query .= $userstable.".".mysql_field_name($fields,$i);
$do_show = 1;
}
}
$query .= " FROM ".$userstable;
for ($i = 0 ; $i < $num ; $i++) {
if ($value[$i] != "") {
if ($do_value != 0) {
$query .= " AND ";
} else {
$query .= " WHERE ";
}
$query .= " ".$userstable.".".mysql_field_name($fields,$i)." ";
$query .= $mod[$i]." \"".$value[$i]."\" ";
$do_value = 1;
}
}
$result=mysql_query($query, $mysql);
$num = mysql_num_fields($result);
$rows = mysql_num_rows($result);
?>
<TABLE WIDTH=500 BORDER=0 align=center>
<TR><TD>
<B>Query: </B><BR><FONT FACE=courier><? echo $query; ?></FONT><BR><BR>
<B>Records matched: </B><FONT FACE=courier><? echo $rows; ?></FONT><BR><BR>
<?
}
/*===============================================*/
/* */
/* Form submitted, e-mail a pipe-delimited file */
/* */
/*===============================================*/
if ($do_query && $email_csv == "on" ) {
if (($email != "") && (ereg("@", $email) > 0)) {
$message = "Query:\n".$query."\n\n";
$message .= "Results matched:\n".$rows."\n\n";
for ($i = 0 ; $i < $rows ; $i++) {
$row = mysql_fetch_row($result);
for ($j = 0 ; $j < $num ; $j++) {
$message .= "".$row[$j]."";
// $message .= "\"".$row[$j]."\"";
if ($j < $num-1) $message .= " | ";
// if ($j < $num-1) $message .= ",";
}
$message .= "\n";
}
mail($email, "RE: Results of your query", $message);
echo "The results have been mailed to you at ".$email."<BR><BR>\n";
} else {
echo "Invalid e-mail or no address specified! Check your settings.";
}
}
/*===============================================*/
/* */
/* Form submitted, output table format */
/* */
/*===============================================*/
if ($do_query && $email_csv != "on" ) {
?>
<DIV ALIGN=center>
<TABLE WIDTH=500 BORDER=1>
<TR>
<?
for ($i = 0 ; $i < $num ; $i++) {
echo "<TH align=left><FONT size=1> ".mysql_field_name($result, $i)."</FONT></TH>";
}
echo "</TR>";
for ($i = 0 ; $i < $rows ; $i++) {
echo "<TR>";
$row = mysql_fetch_row($result);
for ($j = 0 ; $j < $num ; $j++) {
echo "<TD><FONT size=1> ".$row[$j]."</FONT></TD>\n";
}
echo "</TR>";
}
echo "</TABLE><BR><P>Go back using the back button on your browser and send your file to email !</DIV>";
}
/*===============================================*/
/* */
/* No form submitted, output general SELECT form */
/* */
/*===============================================*/
if (!$do_query) {
?>
<BR>
<DIV ALIGN=center>
<TABLE WIDTH="500" BORDER=0 CELLPADDING=0 CELLSPACING=0>
<FORM METHOD="POST" ACTION="get_text.php3">
<TR>
<TH ALIGN=left>Show</TH>
<TH ALIGN=left>Field Name</TH>
<TH ALIGN=left>Operator</TH>
<TH ALIGN=left>Value</TH>
</TR>
<?
for ($i=0 ; $i < $num ; $i++) {
echo "<TR>";
echo "<TD><INPUT TYPE=checkbox CHECKED NAME=\"";
echo "show[".$i."]";
echo "\"></TD>\n";
echo "<TD>".mysql_field_name($fields,$i)." </TD>\n";
?>
<TD>
<SELECT NAME="<? echo "mod[".$i."]"; ?>">
<OPTION>=
<OPTION>!=
<OPTION>>
<OPTION><
<OPTION>>=
<OPTION><=
<OPTION>like
</SELECT></TD>
<?
echo "<TD><INPUT NAME=\"";
echo "value[".$i."]";
echo "\" TYPE=text SIZE=25></TD>\n";
}
echo " <TR>
<TD COLSPAN=\"4\" ALIGN=left>
<BR>
<INPUT TYPE=checkbox NAME=\"email_csv\">E-Mail me the results in a pipe delimited text file (|)
<BR>
Make sure you have entered a valid e-mail address in the setup!
<BR>
Right now your current address is: <B> $email </B><BR>
</TD>
</TR>
<TR>
<TD COLSPAN=\"4\" ALIGN=left>
<INPUT TYPE=\"hidden\" NAME=\"do_query\" VALUE=\"true\">
<INPUT TYPE=submit VALUE=\"Do Query\">
<INPUT TYPE=reset VALUE=\"Clear Form\">
<BR><BR>
<B>Hints:</B>
<LI>Use the like operator (like) to do wildcard matches.
The percent sign (%) matches any characters, and the underscore (_) matches any
single character. (Like the * and . in DOS)
</TD>
</TR>
</FORM></TABLE></DIV>";
mysql_close($mysql);
}
?>
<!-- You can also ignore these two lines, I am still working on the
email addresses, so you can send it to a different address if
you want to.
E-Mail:<INPUT NAME="email" TYPE=text SIZE=30 VALUE="<? echo $email; ?>"><BR>E-Mail:<INPUT NAME="$frm_email" TYPE=text
SIZE=30 VALUE=""><BR> -->
<P><BR><P>
<? require "footer.txt" ?>
</BODY></HTML> |
|
| 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 | | | a function that builds an HTML select list from any mysql table. Categories : PHP, MySQL, HTML and PHP | | | 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 | | | PHP4 MYSQL Authentication Script with cookie. Short & Sweet
Categories : Authentication, Apache, Cookies, PHP, MySQL | | | 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 | | | 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 | |
|
|
|