|
Posted by Tim Streater on 01/02/08 19:22
In article
<e3d66ded-6ef0-4130-8d52-eb33ec3bc6db@l32g2000hse.googlegroups.com>,
paul814@excite.com wrote:
> On Jan 2, 12:33 pm, Tim Streater <tim.strea...@dante.org.uk> wrote:
> > In article
> > <fc01e709-a824-4662-a4f3-1d5fad0d5...@j20g2000hsi.googlegroups.com>,
[snip]
> >
> > // 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?
No, this is going to loop forever. You did not read what I put
previously.
You are doing:
while($row = mysql_fetch_array(mysql_query($sql))){
as I said before, EACH TIME ROUND THE LOOP it is going to do the
mysql_query. The fetch will, each time, get you the first result from
the query so you never exit.
You should be doing something like this:
$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);
and then repeat ALL this for the other query.
Navigation:
[Reply to this message]
|