创建特定尺寸 [英] Creating specific size

查看:41
本文介绍了创建特定尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在html中有一个表.我想在数据库中添加带有php的表.问题出在我的桌子上.我已经做到了

I have a table in html.I want to add that table with php on my database. The problem is with my table. I have done that

CREATE TABLE `playersrb` (
`position` numeric(24) DEFAULT NULL,
`piece_color` enum('B','R') NOT NULL,
`id` numeric(30) DEFAULT NULL,
`last_action` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
)

我有24个职位,我想在我的表中给出这24个职位是那个大小,而不是25个,然后继续..其次,我有B和R,这是颜色(可以).我输入Id是因为这就是我命名我在表格上的图像(它在html中的表格)的方式,我将那些Id:0,Id:1命名为30(因为30是我拥有的最大图像-我不知道)不需要更多.

I have 24 positions and that I want to give in my table that those 24 are that size,not 25 and going on..Second,I have B and R that it is the color (It is ok that).Now I put Id because that's how I name the images I have on my table (the table that it is in my html) ,I name those Id:0 ,Id:1 until 30 (because 30 are the max images I have - I don't want more).

我用那个桌子创建,打开sqlite,转到那个桌子,然后开始放置

I create with that my table,I open sqlite,I go to that table and I start putting

position  piece_color    id   last_action
Null      | R           | 0   | here it was saying the time    
Null      | R           | 1   | the time as previous 
Null      | B           | 2   |  
Null      | B           | 3   |   
Null      | R           | 4   | 
Null      | R           |  5  |
Null      |B            | 6   |

直到30岁末这样
.....我按保存按钮,一切都很好.我去phpmyadmin检查我的表,它不是我创建的.我该怎么做?位置为24,30 id(将是不同的图像).保存30位ID到24位.

and it goes like this until the end of 30
. . . . . I press save the button ,all fine.I go to phpmyadmin to check my table and it wasn't as I created..How can I do that thing?to have position 24 ,30 id (that will be different images ) .Save the 30 Id to 24 position.

已编辑:从我创建的位置和ID的图片中可以看到,我想要的表格就是这样.这个位置就是它属于我的形象的位置.id是图像.我只想从一张桌子传递,我在那个桌子上有位置和id,我想是正确的..当我移动这些图像时他们创建一个具有可变位置和ID的表格.我想将该表传递到我的表中(在数据库表中).如果放置更多图像,我将具有ID 2 以及我拖动的位置.这就是我正在尝试的去做.如您所知,我只想拥有30张图像,每个图像都是唯一的.它们还有其他ID,不一样.更多详细信息,id = 0是图像a,id = 1是图像b.位置是,在图像中,您可以看到它只是您看到的表的编号是我将这些图像移到的位置.

edited: as you can see from the image I have created position and id .The table I want is like those. The position is where it belongs my image. The id is the image.I just want to pass from a table I have the position and the id in that table and I want to be right..When I move those images they create a table with variable position and Id. That table I want to pass into my table (in database table).If I put more images I will have Id 2 and the position which I dragged.That's what I am trying to do. As you can understand I want to have only 30 images.Every image is unique. They have other Id,not the same.More details,id =0 is the image a , the id =1 is the image b .The positions is ,in the image as you can see it is just the number of the table you see it where I move those images.

已编辑

<table class="content-table">
<tr>

<th>Image</th>
<th>Position(TO)</th>
<th>New Position</th>
</tr>
</div>


  
</div>


</div>

<?php

require_once "C/dbconnect.php";
















    
    $sql = "SELECT image, position,new_position  FROM playersrb" ;
    $sql="
    
    SET @old_position = 1;
SET @new_position = 12;

SELECT image
     , position old_order
     , ROUND(CASE WHEN position NOT BETWEEN LEAST(@old_position,@new_position) AND GREATEST(@old_position,@new_position) 
                  THEN position 
                  WHEN position = @old_position THEN @new_position
                  ELSE position+(((@new_position<@old_position)-.1)*12)
                  END 
            ,0) new_order 
  FROM playersrb;
    
    ";
    
    
    
    
    
    
    
    $result = $mysqli-> query($sql);
    
    if($result-> num_rows >0) {
    while ($row = $result-> fetch_assoc()){
    echo "<tr><td>". $row["image"] ."</td><td>". $row["position"] ."</td></tr>";
    }
    echo "</table>";
    }
    else{
    echo "0 result";
    }
    $mysqli->close();


?>
</table>

推荐答案

我不太了解您的问题,但这是重新排列列表的示例...

I don't really understand your question, but here's an example of re-ordering a list...

DROP TABLE IF EXISTS my_table;

CREATE TABLE my_table
(image CHAR(1) NOT NULL PRIMARY KEY 
,position INT NOT NULL
);

INSERT INTO my_table VALUES
('A',1),
('B',2),
('C',3),
('D',4),
('E',5),
('F',6);

所以,假设我们要将图像从位置5拖动到位置2 ...

So, let's say we want to drag the image in position 5 to position 2...

SET @old_position = 5;
SET @new_position = 2;

SELECT image
     , position old_order
     , ROUND(CASE WHEN position NOT BETWEEN LEAST(@old_position,@new_position) AND GREATEST(@old_position,@new_position) 
                  THEN position 
                  WHEN position = @old_position THEN @new_position
                  ELSE position+(((@new_position<@old_position)-.5)*2)
                  END 
            ,0) new_order 
  FROM my_table;

+-------+-----------+-----------+
| image | old_order | new_order |
+-------+-----------+-----------+
| A     |         1 |         1 |
| B     |         2 |         3 |
| C     |         3 |         4 |
| D     |         4 |         5 |
| E     |         5 |         2 |
| F     |         6 |         6 |
+-------+-----------+-----------+

这是一个更完整的示例,使用一些PHP输出到HTML ...也许其他人可以使它更漂亮...

Here's a fuller example, using some PHP to output to HTML... perhaps someone else can make it pretty...

<?php
//simple_sorter.php
//Preamble

/*
A simple row repositioning script.
This is using a simple $_GET to determine which row is repositioned.
So you need to supply a source and a target in the url, e.g.:

https://path/to/simple_sorter.php?old_position=5&new_position=2

There is no error checking, so it can quite easily fall apart, and because   
the SELECT comes befpre the UPDATE, you won't see any changes until the 
next time you load the page.
*/

//Data Creation Statements

/*
DROP TABLE IF EXISTS my_table;

CREATE TABLE my_table
(image CHAR(1) NOT NULL PRIMARY KEY
,position INT NOT NULL
);

INSERT INTO my_table VALUES
('A',1),
('B',2),
('C',3),
('D',4),
('E',5),
('F',6);
*/

require('path/to/pdo/connection/stateme.nts');

//My understanding is that the following is needed 
  in order to replace (every instance within the 
  query of) :old_position and :new_position with 
  their corresponding values

$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, TRUE);

//and now to the code...

$query = "
SELECT *
  FROM my_table
 ORDER
    BY position
";
$stmt  = $pdo->prepare($query);
$stmt->execute();
$data  = $stmt->fetchAll();
print_r($data);

$query = "
UPDATE my_table x
  JOIN
     ( SELECT image
            , position old_order
            , ROUND(CASE WHEN position NOT BETWEEN LEAST(:old_position,:new_position) AND GREATEST(:old_position,:new_position)
                         THEN position
                         WHEN position = :old_position THEN :new_position
                         ELSE position+(((:old_position>:new_position)-.5)*2)
                         END
                   ,0) new_order
         FROM my_table
     ) y
    ON y.image = x.image
   SET position = new_order
";

$old_position  = $_GET['old_position'];
$new_position  = $_GET['new_position'];

$stmt  = $pdo->prepare($query);
$stmt->execute(array('old_position' => $old_position,'new_position' => $new_position));

?>

输出(例如,取决于使用的值以及使用频率)...

Outputs (for instance, and depending what values were used, and how often)...

Array
(
    [0] => Array
        (
            [image] => A
            [position] => 1
        )

    [1] => Array
        (
            [image] => D
            [position] => 2
        )

    [2] => Array
        (
            [image] => E
            [position] => 3
        )

    [3] => Array
        (
            [image] => B
            [position] => 4
        )

    [4] => Array
        (
            [image] => C
            [position] => 5
        )

    [5] => Array
        (
            [image] => F
            [position] => 6
        )

)

这篇关于创建特定尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆