|
Posted by paul814 on 01/02/08 17:40
On Jan 2, 12:33 pm, Tim Streater <tim.strea...@dante.org.uk> wrote:
> In article
> <fc01e709-a824-4662-a4f3-1d5fad0d5...@j20g2000hsi.googlegroups.com>,
>
> paul...@excite.com wrote:
>
> [snip]
>
>
>
>
>
> > OK I think I am getting closer, thanks for the help.
> > I am getting this error:
> > Warning: mysql_num_rows(): supplied argument is not a valid MySQL
> > result resource in C:\xampp\htdocs\production\date2.php on line 26
>
> > this is my code as of now:
> > Generating and emailing report for:
> > <?php
> > $today = date("M j, Y,");
> > echo $today;
>
> > $host="localhost";
> > $user="root";
> > $pass="";
> > $db="productiondb";
> > $con = mysql_connect($host, $user, $pass);
>
> > if (!$con)
> > {
> > die('Unable to connect: ' . mysql_error());
> > }
> > mysql_select_db($db, $con) or die('Unable to connect: ' .
> > mysql_error());
>
> > // Get results from first table
> > $sql = "SELECT * FROM editorial WHERE editorialdate LIKE '$today%'
> > ";
> > $sql2 = "SELECT * FROM prepress WHERE prepressdate LIKE '$today%' ";
>
> > // Begin our email body
> > $messageBody = "Production Report follows for all departments: /r/
> > n";
>
> <----- try doing a query *before* asking how many rows it generated.
>
> $result = mysql_query ($sql);
> $numrows = mysql_num_rows ($result);
> if ($numrows>0)
> {
> while ($row = mysql_fetch_array ($result))
> {
> // add first results
> ...
> }
> }
> mysql_free_result ($result);
>
> // now do the same for the other query
>
> > if (mysql_num_rows($result)) { // if there are results
> > // Add results from first query to email
> > while($row = mysql_fetch_array(mysql_query($sql))){
> > $messageBody .= "Editorial Date: " . $row['editorialdate'];
>
> How do you expect this to work? Every time round the while loop, you do
> the mysql_query again and fetch the first row of the results. You
> shouldn't nest these calls.
>
> I would also suggest a more tidy layout which will help you debug more
> easily.
OK I am seeing this now, after adding this:
$result=mysql_query($sql);
It looks like my page is just in a loop, because it just continues to
try to load.
Looking at this code I think it will loop through and do a search on
$SQL until it does not find any other records matching, than it will
go down and do the same thing for $sql2 while there is something
there, all the time putting it into $messagebody
Am I close? What am I doing wrong?
most updated code as of now...now it looks like the page is just
looping......
Generating and emailing report for:
<?php
$today = date("M j, Y,");
echo $today;
$host="localhost";
$user="root";
$pass="";
$db="productiondb";
$con = mysql_connect($host, $user, $pass);
if (!$con)
{
die('Unable to connect: ' . mysql_error());
}
mysql_select_db($db, $con) or die('Unable to connect: ' .
mysql_error());
// Get results from first table
$sql = "SELECT * FROM editorial WHERE editorialdate LIKE '$today%'
";
$sql2 = "SELECT * FROM prepress WHERE prepressdate LIKE '$today%' ";
// Begin our email body
$messageBody = "Production Report follows for all departments: /r/
n";
$result=mysql_query($sql);
if (mysql_num_rows($result)) { // if there are results
// Add results from first query to email
while($row = mysql_fetch_array(mysql_query($sql))){
$messageBody .= "Editorial Date: " . $row['editorialdate'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Name: " . $row['editorialname'];
$messageBody .= "/r/n";
$messageBody .= "Editorial Comments: " . $row['editorialcomments'];
$messageBody .= "/r/n";
}
// Add results from second query to email
while($row = mysql_fetch_array(mysql_query($sql2))) {
$messageBody .= "PrePress Date: " . $row['prepressdate'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Name: " . $row['prepressname'];
$messageBody .= "/r/n";
$messageBody .= "Prepress Comments: " . $row['prepresscomments'];
$messageBody .= "/r/n";
}
}
mysql_close($con); //closes the connection to the DB
// Send email
ini_set("SMTP", "texchange.company.com");
ini_set("smtp_port", "25");
$headers = "From: Prod.Report_PREPRESS@company.com";
mail("paul@company.com","Production Report",$messageBody,$headers);
?>
[Back to original message]
|