Jump to content

[SOLVED] changing a variable by a link


penguin0

Recommended Posts

I already know how to do this, but I am getting incorrect results.

 

$mnum = intval($_REQUEST['number']);

if ($mnum > 0) {
$pmove = intval($_REQUEST['pmove']);
$smove = intval($_REQUEST['smove']);
$mpos = intval($_REQUEST['position']);

if ($pmove = "1") {
$sql = "UPDATE menu SET position = $mpos + $pmove WHERE number = $mnum";
$result = @mysql_query($sql, $link) or die(mysql_error());

}

if ($smove = "1") {
$sql = "UPDATE menu SET position = $mpos - $smove WHERE number = $mnum";
$result = @mysql_query($sql, $link) or die(mysql_error());
}

}

$result = mysql_query( "SELECT number, name, link, position, isparent, private, modified FROM menu WHERE private = 1 ORDER BY position" );
$num_rows = mysql_num_rows( $result );
while ( $row = mysql_fetch_array( $result ) ) {

$mnumber = $row['number'];
$mname = $row['name'];
$mlink = $row['link'];
$mposition = $row['position'];
$misparent = $row['isparent'];
$mprivate = $row['private'];
$modified = $row['modified'];

if ($misparent == "0") {
$starttag = "<td class=ac><a href=\"editmenu.php?number=$mnumber\"><img src=\"/romac/images/info.gif\" border=\"0\"></a></td><td class=ac>$mposition</td><td><a href=\"?position=$mposition&smove=1&pmove=0&number=$mnumber\">Move Up</a><br /><a href=\"?position=$mposition&pmove=1&smove=0&number=$mnumber\">Move Down</a></td><td class=\"off\" onmouseover=\"this.className=\" onmouseout=\"this.className=\" height=\"30\" align=\"left\" valign=\"middle\"><a href=\"$mlink\" class=\"left_menu_text\">";
$endtag = "</a></td><td>$modified</td><td class=ac><a href=\"delmenu.php?number=$mnumber\"><img src=\"/romac/images/del.png\" border=\"0\"></td></tr>";

} else {

$starttag = "<td class=ac><a href=\"editmenu.php?number=$mnumber\"><img src=\"/romac/images/info.gif\" border=\"0\"></a></td><td class=ac>$mposition</td><td><a href=\"?position=$mposition&smove=1&pmove=0&number=$mnumber\">Move Up</a><br /><a href=\"?position=$mposition&pmove=1&smove=0&number=$mnumber\">Move Down</a></td><TH><br>";
$endtag = "<br><br></TH></td><td>$modified</td><td class=ac><a href=\"delmenu.php?number=$mnumber\"><img src=\"/romac/images/del.png\" border=\"0\"></td></tr>";
}

$menu_block2 .= "
<tr>$starttag$mname</a>$endtag";
}

$result = mysql_query( "SELECT number, name, link, position, isparent, private, modified FROM menu WHERE private = 0 ORDER BY position" );
$num_rows2 = mysql_num_rows( $result );

while ( $row = mysql_fetch_array( $result ) ) {

$mnumber = $row['number'];
$mname = $row['name'];
$mlink = $row['link'];
$mposition = $row['position'];
$misparent = $row['isparent'];
$mprivate = $row['private'];
$modified = $row['modified'];

if ($misparent == "0") {
$starttag = "<td class=ac><a href=\"editmenu.php?number=$mnumber\"><img src=\"/romac/images/info.gif\" border=\"0\"></a></td><td class=ac>$mposition</td><td><a href=\"?position=$mposition&smove=1&pmove=0&number=$mnumber\">Move Up</a><br /><a href=\"?position=$mposition&pmove=1&smove=0&number=$mnumber\">Move Down</a></td><td class=\"off\" onmouseover=\"this.className=\" onmouseout=\"this.className=\" height=\"30\" align=\"left\" valign=\"middle\"><a href=\"$mlink\" class=\"left_menu_text\">";
$endtag = "</a></td><td>$modified</td><td class=ac><a href=\"delmenu.php?number=$mnumber\"><img src=\"/romac/images/del.png\" border=\"0\"></td></tr>";

} else {

$starttag = "<td class=ac><a href=\"editmenu.php?number=$mnumber\"><img src=\"/romac/images/info.gif\" border=\"0\"></a></td><td class=ac>$mposition</td><td><a href=\"?position=$mposition&smove=1&pmove=0&number=$mnumber\">Move Up</a><br /><a href=\"?position=$mposition&pmove=1&smove=0&number=$mnumber\">Move Down</a></td><TH><br>";
$endtag = "<br><br></TH></td><td>$modified</td><td class=ac><a href=\"delmenu.php?number=$mnumber\"><img src=\"/romac/images/del.png\" border=\"0\"></td></tr>";
}

$menu_block3 .= "
<tr>$starttag$mname</a>$endtag";
}

if ($num_rows > "0") {
echo "<a class=\"orange_link\" href=\"addmenu.php\">Add Menu</a><br /><br />\n";
echo "<table border=0 cellpadding=1 cellspacing=1 class=\"ptable\" width=\"100%\"><tr><TH colspan=\"6\">Private Menu layout</TH></tr>\n
<tr><TH>Edit</TH><TH>Position</TH><TH>Move</TH><TH>Structure</TH><TH>Modified</TH><TH>Del</TH>";
echo "$menu_block2";
echo "<tr><td colspan=\"6\">";
echo "Total Menus:  $num_rows";
echo "</td></tr></table>";
}

if ($num_rows2 > "0") {
echo "<br><table border=0 cellpadding=1 cellspacing=1 class=\"ptable\" width=\"100%\"><tr><TH colspan=\"6\">Public Menu layout</TH></tr>\n
<tr><TH>Edit</TH><TH>Position</TH><TH>Move</TH><TH>Structure</TH><TH>Modified</TH><TH>Del</TH>";
echo "$menu_block3"; 
echo "<tr><td colspan=\"6\">";
echo "Total Menus:  $num_rows2"; 
echo "</td></tr></table></td></tr>";
}

 

I know there is a lot of code, but for some reason, when I click the link <a href=\"?position=$mposition&pmove=1&smove=0&number=$mnumber\">Move Down</a>

 

It changes pmove to 1 and smove to 1.  I have no idea why this is happening, otherwise I would not post all this.  Also it will always -1, even if I click move down.

Link to comment
https://forums.phpfreaks.com/topic/54049-solved-changing-a-variable-by-a-link/
Share on other sites

I am not sure if this has anything to do with it, but when you are evaluating a condition you must use 2 equal signs (==) vs (=).

 

if ($pmove = "1")
if ($smove = "1")

 

Basically what you are doing is setting these values to 1 (which then equates to true so they will always be executed). 

 

You also should use single quotes instead of double quotes as PHP then has to parse what is inside the double quote to see if there is a variable in there.

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.