Pioden Posted May 22, 2008 Share Posted May 22, 2008 Sorry to ask such a vague question but this has me stumped and I don't see where its going wrong! I tested sub-versions of this code and everything worked fine BUT once I but it into the main code file where it lives it doesn't work quite right. The bit which doesn't work is commented "Check for and remove any subsubpages" - it simply doesn't do anything. In theory it should loop through the $sub_page_uid results and set some db entries to NULL . I can't see any typo's and the code executes but it simply doesn't do anything! Waaaaaaah. Where did I do wrong? TIA // Change order for Principal page if ($principal == "y") { // Find page UID's for sub pages so we can remove subsubpages $sql = "SELECT page_uid FROM navigation WHERE subpageof = '$sent_page_uid'"; $result = @mysql_query($sql,$connection) or die("Couldn't execute first query.". $php_errormsg . mysql_error()); while ($row = mysql_fetch_array($result)) { $sub_page_uid = $row['page_uid']; if (!empty($sub_page_uid)) { // Check for and remove any subsubpages $sql = "UPDATE navigation SET principal=NULL,pageorder=NULL,subpageof=NULL,subsubpageof=NULL WHERE subsubpageof = '$sub_page_uid'"; $result = @mysql_query($sql,$connection) or die("Couldn't execute third query.". $php_errormsg . mysql_error()); } } // Remove subpages $sql = "UPDATE navigation SET principal=NULL,pageorder=NULL,subpageof=NULL,subsubpageof=NULL WHERE subpageof = '$sent_page_uid'"; $result = @mysql_query($sql,$connection) or die("Couldn't execute third query.". $php_errormsg . mysql_error()); } // End of principal page change Quote Link to comment Share on other sites More sharing options...
beboo002 Posted May 22, 2008 Share Posted May 22, 2008 i think when ur script run then it find same variable declare twice which take diffrent type of value that the reason . Quote Link to comment Share on other sites More sharing options...
Pioden Posted May 22, 2008 Author Share Posted May 22, 2008 Nope. I just rechecked the script and no variables are declared twice. The important one here is $sub_page_uid and that only occurs in the code I posted. Strange. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 22, 2008 Share Posted May 22, 2008 You have a while() loop that is fetching rows from $result, but inside of that loop you are preforming another query which uses $result and so replaces what was originally in $result. $result won't contain what your outer while() loop expects and it will not operate as expected. Quote Link to comment Share on other sites More sharing options...
DyslexicDog Posted May 22, 2008 Share Posted May 22, 2008 Indenting your code makes things easier to read. <?php // Change order for Principal page if ($principal == "y") { // Find page UID's for sub pages so we can remove subsubpages $sql = "SELECT page_uid FROM navigation WHERE subpageof = '".$sent_page_uid."'"; $result = @mysql_query($sql,$connection) or die("Couldn't execute first query. ". $php_errormsg . mysql_error()); while ($row = mysql_fetch_array($result)) { $sub_page_uid = $row['page_uid']; print_r($row); if (!empty($sub_page_uid)) { // Check for and remove any subsubpages $sql = "UPDATE navigation SET principal=NULL,pageorder=NULL,subpageof=NULL, subsubpageof=NULL WHERE subsubpageof = '".$sub_page_uid."'"; $result2 = @mysql_query($sql,$connection) or die("Couldn't execute query loop. ". $php_errormsg . mysql_error()); } } // Remove subpages $sql = "UPDATE navigation SET principal=NULL,pageorder=NULL, subpageof=NULL,subsubpageof=NULL WHERE subpageof = '".$sent_page_uid."'"; $result3 = @mysql_query($sql,$connection) or die("Couldn't execute third query.". $php_errormsg . mysql_error()); } // End of principal page change ?> Quote Link to comment Share on other sites More sharing options...
Pioden Posted May 22, 2008 Author Share Posted May 22, 2008 You have a while() loop that is fetching rows from $result, but inside of that loop you are preforming another query which uses $result and so replaces what was originally in $result. $result won't contain what your outer while() loop expects and it will not operate as expected. Ach. Of course. That's why it tested fine but balked during then next stage. Thanks a million. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.