|
|
|
| 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 : |
2 of 5 (graded 4 times) |
| Viewed : |
10085 |
| 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 | | | How to thread a list of messages in database
and show it in a treelike structure Categories : PHP, MySQL, Databases | | | Simple conversion functions to change MySQL dates to arrays, arrays to MySQL dates.
Categories : PHP, Arrays, Date Time, Databases, MySQL | | | Checks Date-Input from HTML-Forms and converts to YYYY-MM-DD Format for MySQL Date-Fields Categories : MySQL, Date Time, PHP, Databases | | | Specify your connection settings and create a link to a MySQL database. Categories : PHP, PHP Classes, Databases, MySQL, Beginner Guides | | | Paginator - a class that can help you to split MySQL database query result sets to pages. Categories : MySQL, Databases, HTML, PHP | | | Warning: Unknown(): A session is active. You cannot change the session module's ini settings at this time. in Unknown on line 0 Categories : PHP, Sessions, Databases, MySQL | | | Complex paging with no resultset limit Categories : PHP, MySQL, Databases, Output Control, HTML and PHP | | | php-gtk mysql querying tool Categories : PHP-GTK, MySQL, PHP, Databases | | | mediaCat-GTK v2.0.0 - an mp3/cd/dvd cataloging utility written in php-gtk which interfaces with mysql and ms access (or db supported by PHP's Unified ODBC Functions) Categories : PHP, MySQL, MS Access, Utilities, Databases | | | Zip code range and distance calculation class v1.0.0 Categories : PHP, Databases, MySQL, Zip Code | | | Phorum, MySQL, Language, UK date format, MySQL UK Date format Categories : PHP, Date Time, Strings, MySQL, Databases | | | MySQL Connection/Query Class Categories : Databases, MySQL, PHP, PHP Classes | | | Multi-table database search for your WAP-enabled device. Uses PHP and MySQL. No WMLscript. Categories : WAP, WML, PHP, MySQL | | | phpFormGenerator for Dynamic Form Generation from MySQL Categories : PHP, PHP Classes, MySQL, Databases, HTML and PHP | |
| |
| |
|