[PHP] Query refuses to recurse all rows
Hi, In the following code, only the first row from query1 displays along with the display stuff from query3. The problem: query1 refuses to recurse to the next and following rows. It appears that the sub-queries in the main query cause the $row++; not to work. Is there some conditional that might it prompt it to do so? I'm stumped - worked at variations for a few days. Any help, pointers, suggestions most gratefully welcome! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Query refuses to recurse all rows {RESOLVED]
Thanks Wolf and Chris, That did the trick -- now I just have to clean up the order a bit. Amazing how another's view can see the problem so clearly -- I was way too close, what with otehr coding - should've seen it! Regards, Andre (celtic) On Wednesday 28 May 2008, Wolf wrote: > Chris wrote: > >>$numrows1 = pg_numrows($result1); > >>$row = 0; > >>do > >>{ > >>$myrow = pg_fetch_array($result1, $row); > > > > > > > >>$numrows2 = pg_numrows($result2); > >>$row = 0; > >>do > >>{ > >>$myrow = > >> pg_fetch_array($result2, $row); > > > > You're overwriting your variables. > > > > $myrow from result 1 is being killed off when it gets into the $myrow > > loop from result 2. > > Yeah, what Chris said! > > When you are looping inside another piece, make sure to change up all > your variables. > use a $j inside an $i, a $l inside a $k, $rowa inside a $row > > Woulda saved yourself a day of playing... > > Remember, the variable scope changes inside a function or class, but > outside of that they pretty much run the whole length of the script. > > HTH, > Wolf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Query refuses to recurse all rows
Hi Jim, Actually, after I got the code working, I eliminated the 'exit' and skipped the empty query instead to the next block. Ahh! That cryptic header relocate: If the db conn or code is buggy fails, it redirects to a nice page telling the user that the db 'Is down for maintenance' or somesuch. The primary reason for it: debugging -- it shows up in my logs with the conn that failed, and helps pinpoint problems within the code. Has saved my butt a few times particularly on my main site that is heavily accessing the db with lots of sub-code to wade through. Thanks for the nifty advice -- code sure looks pretty now and works like a charm! Regards, Andre (celtic) On Wednesday 28 May 2008, Jim Lucas wrote: > If I may, I would like to suggest a few other changes that you might like. > > first off, don't use counters, they waist cpu cycles. Try this code out. > > > > include("dbc.php"); > if (!$db){ $_SESSION['db'] = "select-thread"; session_write_close(); > > // Wt??? what is this for? > header("location: db.php");} > # > # > # > # why are you displaying anything after a header('Location ') call? > > > // Build first query > $query1 = "SELECT * > FROM replies > WHERE mid = '{$_SESSION['mid']}'"; > > // Execute query. if it fails, skip this block > if ( ($result1 = pg_exec($db, $query1)) !== false ) { > >// if we are here, the query worked. Loop through results >while ( $row1 = pg_fetch_assoc($result1) ) { > > /* display stuff */ > > // Build second query > $query2 = "SELECT * > FROM subs > WHERE mid = '{$_SESSION['mid']}' > ANDrid = '{$row1['rid']}'"; > > > // Execute second query, if it fails, skip this block > if ( ($result2 = pg_exec($db, $query2)) !== false ) { >// If we are here, the query worked. Loop through results >while ( $row2 = pg_fetch_assoc($result2) ) { > /* display stuff */ >} > } > > // Build third query > $query3 = "SELECT * > FROM subs > WHERE subsid = '{$_SESSION['subsid']}' > ANDrid = '{$row1['rid']}' > ANDresponded = '1'"; > > // Execute third query, if it fails, skip this block > if ( ($result3 = pg_exec($db, $query3)) !== false ) { >// If we are here, the query worked. Loop through results >while ( $row3 = pg_fetch_assoc($result3) ) { > /* display stuff */ >} > } >} > } > > ?> > > My guess is is that you don't want to actually 'exit;' the script if a > query fails, you just wanted to skip displaying any data for it. I > might be wrong, but I adjusted my example to factor this in. > > Inquiring minds want to know. Why is it that you have a header() call > with a location header that tells this script to go somewhere else, but > then you display a bunch of data after the header call is sent to the > client? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Bulk Email Problems
Hi, I coded a bulk emailer for our newsletter that worked fine for the last few years resulting in many requests for forgotten passwords and renewed site activity. Last year, we sent it again, after a few minor code changes, and had no response whatsoever. Unfortunately, I no longer have the backup copy of the original code. So, I assume that the code has an error that I can't see. Perhaps someone might see an obvious error in the code (I'm just too close to it to see it objectively. The code page loads from a secured authorized connection, and iterates through a postgresql db table for names and email addresses. I've broken the email packets to 50, and verify that each has been sent. Any help greatly appreciated -- I'm afraid to check it live with actual names/email addresses, though it works fine for a few duds that I have salted in the sponsor table. Code snippet: POST submit value is {$_POST['submit']}"; print "RUN value is $run"; print "RUN SESSION value is {$_SESSION['run']}"; include("dbc.php"); switch ($run) : case "1" : /* sid to 100-149 */ $current = "(SID 100-149)"; $query = "SELECT sid,sfname,ssname,smail FROM sponsor WHERE sid > 99 AND sid < 150 AND sid != 100 AND sid != 105 AND sid != 107 AND sid != 109 AND sid != 111 AND sid != 113 AND sid != 114 AND sid != 119 AND sid != 130 AND sid != 131 AND sid != 148 AND sid != 165 AND sid != 166 ORDER BY sid ASC"; $run = 2; $_SESSION['run'] = 2; session_write_close(); break; case "2" : /* sid to 150-199 */ $current = "(SID 150-199)"; $query = "SELECT sid,sfname,ssname,smail FROM sponsor WHERE sid > 149 AND sid < 200 AND sid != 100 AND sid != 105 AND sid != 107 AND sid != 109 AND sid != 111 AND sid != 113 AND sid != 114 AND sid != 119 AND sid != 130 AND sid != 131 AND sid != 148 AND sid != 165 AND sid != 166 ORDER BY sid ASC"; $run = 3; $_SESSION['run'] = 3; session_write_close(); break; . . . . case "11" : /* sid 500 + */ $current = "(SID 600+)"; $query = "SELECT sid,sfname,ssname,smail FROM sponsor WHERE sid > 599 ORDER BY sid ASC"; $run = 12; $_SESSION['run'] = 12; session_write_close(); break; case "12" : $run = "'s complete!"; header("location: newsletter.php"); break; case "TEST RUN"; print "TEST RUN: NO further processingCheck incoming email!"; break; endswitch; /* Text and headers for email */ $message = "Dear $fname, .. admin"; $sender = "[EMAIL PROTECTED]"; $subject = "Newsletter June 2008"; $recipient_fullname = "$fname $sname"; $recipient = "$recipient_fullname <$smail>"; // call mail function $headers = "From: $sender"; $response = mail($recipient, $subject, $message, $headers); if ($response[0] == 0) { print "Run #$run-$current Newsletter email processed for ($sid) - $fname $sname$smail"; } else { print "Run #$run-$current ERROR processing for ($sid) - $fname $sname$smail"; } } } ?> Tia, Andre (celtic) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php