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: <snip> > 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. > > > <?php > > include("dbc.php"); > if (!$db){ $_SESSION['db'] = "select-thread"; session_write_close(); > > // Whhhhaaaattttt........??? 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']}' > AND rid = '{$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']}' > AND rid = '{$row1['rid']}' > AND responded = '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