Jump to content

What's wrong here?


Pioden

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.