Advertisement

06.17.2008 at 04:37PM PDT, ID: 23493616
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.8

Move the records up/down (sort) in database PHP

Asked by zollgut in MySQL Server, Databases Miscellaneous

Tags: , , , , , ,

Hi, I'm trying to sort the records in a table by using an 'up' and 'down' buttons (images).

Basically it should swap the position of the two records in the database:
example records A B C D - When you click the 'up' button for C the records should now read A C B D.

I'm using 'id' which is the primary key and 'order' (integer with default as 0) which should hold the value of the order of the records.

Been struggling for a long time on this one, your help would be really appreciated!!! :D

I'm attaching the sort_toptip.php page as a code snippet, the code with the buttons which call it are below:

---------------------------------------------------

<?php

// Create an object (instance) of the DbConnector
$connector = new DbConnector();

// Execute the query to retrieve articles
$result = $connector->query('SELECT id,day,month,year,location,venue FROM TopTips ORDER BY id ASC LIMIT 0,1000');

// Get an array containing the results.
// Loop for each item in that array
echo '<h3>Top Tips</h3>';

while ($row = $connector->fetchArray($result)){

echo '<h6>';
echo '<span class="courselist">';
echo $row['day'];
echo '</span>';
echo '<span class="courselist">';
echo $row['month'];
echo '</span>';
echo '<span class="courselist">';
echo $row['year'];
echo '</span>';
echo '<span class="courselist">';
echo $row['location'];
echo '</span>';
echo '<span class="courselist">';
echo $row['venue'];
echo '</span>';
echo '<span class="courselist">';
echo '<a href="edit_toptip.php?id='.$row['id'].'">EDIT</a> /';
echo '</span>';
echo '<span class="courselist">';
echo '<a href="delete_toptip.php?id='.$row['id'].'">DELETE</a>';

echo '<span class="sorting"> ';
echo ' <a href="sort_toptip.php?id='.$row['id'].'&move=up"><img src="../images/up.gif" border="0" /></a>';
echo '</span>';

echo '<span class="sorting">';
echo '<a href="sort_toptip.php?id='.$row['id'].'&move=down"><img src="../images/down.gif" border="0" /></a>';
echo '</span>';

echo '</span>';
echo '</h6>';

}
?>
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
<?php
 
// Require the database class
require_once('../includes/DbConnector.php');
 
// Create an object (instance) of the DbConnector
$connector = new DbConnector();
 
 
if (isset($_GET['move']) && $_GET['move'] == "up"){
 
$connector->query("UPDATE `TopTips` SET `order` = `order` - 1 WHERE `order` = " . $_GET['order']+1);
$connector->query("UPDATE `TopTips` SET `order` = `order` + 1 WHERE `id` = " . $_GET['id']);
 
print "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">";
 
}
 
if (isset($_GET['move']) && $_GET['move'] == "down"){
 
$connector->query("UPDATE `TopTips` SET `order` = `order` + 1 WHERE `order` = " . $_GET['order']-1);
$connector->query("UPDATE `TopTips` SET `order` = `order` - 1 WHERE `id` = " . $_GET['id']);
 
print "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">";
 
}
 
 
?>
[+][-]06.17.2008 at 06:34PM PDT, ID: 21809180

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MySQL Server, Databases Miscellaneous
Tags: php mySQL, update record, database, sort, sorting save record, edit record, problem
Sign Up Now!
Solution Provided By: matthewstevenkelly
Participating Experts: 1
Solution Grade: A
 
 
[+][-]06.17.2008 at 07:26PM PDT, ID: 21809559

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.17.2008 at 07:42PM PDT, ID: 21809610

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.17.2008 at 08:08PM PDT, ID: 21809706

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.17.2008 at 08:22PM PDT, ID: 21809763

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.17.2008 at 09:10PM PDT, ID: 21809973

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.17.2008 at 09:16PM PDT, ID: 21810013

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.17.2008 at 09:18PM PDT, ID: 21810021

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.18.2008 at 04:20AM PDT, ID: 21811689

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.18.2008 at 08:13AM PDT, ID: 21813783

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906