Jump to content

Recommended Posts

First question is, what does it do?  I've searched, but all I can find are people trying to use or suggesting others use it and the various tangents that come with it. 

 

For example:  What is this query saying?

SELECT * FROM $table order by ABS(orderList) ASC

The reason I'm asking is I came across some code that should let me/user rearrange items in a data table from the front end.  Better, it works on an tablet via touch.  Trying to adapt it to my specific needs is where I'm running into the problem.

 

(works with a mouse/trackpad as well)

 

http://hoosierhoopsreport.com/scripts/dragdrop/#sg

 

 

Here is the original query code:

$sql = mysql_query("SELECT * FROM $table order by ABS(orderList) ASC");
$num = mysql_num_rows($sql);
while($row = mysql_fetch_assoc($sql)){

echo "<li class='ui-state-default' id='ID_".$row['list_id'] ."'>".$row['title']."</li>";
}
}

and here is the code the saves it back to the data table:

$order = $_POST['ID'];
$k  = 1;

$str = implode(",", $order);

foreach ($order as $k => $val){
	
	$query  = "UPDATE $table SET `orderList` = ".$k;
	$query .= " WHERE `list_id` = ".$val;
	
	$res = mysql_query($query);
	
	if (!$res)
		echo mysql_error()."<br />";
	
	
}

I'm trying to change this around to fit the columns of data that I have, and I'm having an issue since it's a little more involved than a simple list.  I got it to echo my list, and the ability to manually change the order on the screen works.  However, how is it recognizing the order on the screen, and how do I 'save' that back to my data table?  

 

 

Link to comment
https://forums.phpfreaks.com/topic/278284-order-by-abs-issue-and-a-question/
Share on other sites

Your post s very confusing. One thing you ask has nothing to do with another. Your initial question was about ABS(). In MySQL it is a math function that returns the absolute value of a number. Put simply, the absolute value is simply the positive value of a number. So, the absolute value of 3 is 3 and the absolute value of -3 is also 3.

 

I'm really confused by your comments about ordering results and mouse/trackpad as those have nothing to do with the query.

I'm sure it was confusing.  My goal is to have front end (only to me) control of one of my data tables.  I found this script that accomplishes that (letting me do it via touch on a tablet) with test data, and I'm trying to apply it to my needs.  The link I provided shows it in action, but as I adjust the columns it saves to I'm not able to get the desired results.  

 

I didn't know what ABS referred to, and now that I do, it doesn't help me understand how this takes what shows on the screen and updates my data table.

I'm getting a result now, just not a desired one.  Moving a player in the top 10 to the top of the list, makes him zero.  Everyone else lines up 1-9.  Moving a second player to the top causes everyone below him to adopt that number, so if I moved the 6th player there, from five to zero turn into a six.

OK, it seems you've copied and pasted several different pieces of code (HTML, AJAX, PHP, MySQL) which are designed to work together. And, now you are trying to modify those pieces of code to work differently. But, if you don't understand the code you are using you are going to have a tight time knowing what to change and what not to change. You may need to make changes in the HTML, AJAX, PHP or MySQL, several of them, or all of them.

 

I would start by seeing what is sent by the JavaScript/AJAX code when the order is changed. Then look at the PHP code to see how it would be processed.

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.