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
https://forums.phpfreaks.com/topic/106743-whats-wrong-here/
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
https://forums.phpfreaks.com/topic/106743-whats-wrong-here/#findComment-547253
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
https://forums.phpfreaks.com/topic/106743-whats-wrong-here/#findComment-547261
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
https://forums.phpfreaks.com/topic/106743-whats-wrong-here/#findComment-547293
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.