|
Posted by Tim Streater on 01/02/08 17:33
In article
<fc01e709-a824-4662-a4f3-1d5fad0d5660@j20g2000hsi.googlegroups.com>,
paul814@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.
Navigation:
[Reply to this message]
|