/    Sign up×
Community /Pin to ProfileBookmark

Interchange Menu help please???

hi frens i have some codes that i made still got bug here, and i am new to php logic neeed lots of help here… the point is that on click wheter is up or down i need my menu display can be moved to any position. examples :

menu1
menu2
menu3
menu4
menu5

become:

menu1
menu2
menu5
menu3
menu4

in my code error everytime i move yes it moved, but i in the database i get the same input numbers, that makes the ordering id became duplicate numbers

pls someone help me, really appreciate ur help ?

here is the code i make now :

[QUOTE]

<?php

$q = ”;

$c = 0;

$q .= ‘SELECT * FROM `tes` ‘;

$q .= ‘ORDER BY `order` ASC ‘;

$r = mysql_query( $q, $l ) or die(‘query failed:<br />’.$q );

$tes = mysql_num_rows($r);

for($i=1;$i<=$tes;$i++) {
$tesisi = mysql_fetch_array($r);
?>
<table width=”50%” border=”1″>
<tr>
<td><?php echo $tesisi[‘menuname’]; ?></td>
<td><a href=”testorder.php?move=up&id=<?php echo $tesisi[‘id’]; ?>&order=<?php echo $tesisi[‘order’]; ?>”>up</a> | <a href=”testorder.php?setorder=down&id=<?php echo $tesisi[‘id’]; ?>”>down</a></td>
</tr>
</table>
<?php
}
$getmove = trim($_GET[‘move’]);
$getorder = trim($_
GET[‘order’]);
$getid = trim($_GET[‘id’]);
if($getmove == “up”) {
$setmove = $getorder – 1;

$q5 .= ‘UPDATE `tes` SET ‘;

$q5 .= ‘ `order` = ‘.$setmove.’ ‘;

$q5 .= ‘WHERE `id` = ‘.$getid.’ ‘;

$q5 .= ‘ORDER BY `order` ASC ‘;

$r = mysql_query( $q5, $l ) or die(‘query failed:<br />’.$q5 );

$movebefore = $setmove + 1;
$idbefore = $getid – 1;

$q6 .= ‘UPDATE `tes` SET ‘;

$q6 .= ‘ `order` = ‘.$movebefore.’ ‘;

$q6 .= ‘WHERE `id` = ‘.$idbefore.’ ‘;

$q6 .= ‘ORDER BY `order` ASC ‘;

$r = mysql_query( $q6, $l ) or die(‘query failed:<br />’.$q6 );

echo “<script type=”text/javascript”>window.location=’testorder.php’;</script>”;

/*
print $q5;
print “<br>”.$q6;
*
/
}
?>

[/QUOTE]

many thx frens and master php ?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@superbogelauthorApr 25.2009 — can someone help please?
×

Success!

Help @superbogel spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...