简体   繁体   English

将aukciono_id从一个表转移到另一个表

[英]Transfer aukciono_id from one table to another

I am trying to transfer "aukciono_id" from one table to another. 我正在尝试将“ aukciono_id”从一个表转移到另一个表。 I was trying to do it using a single while loop and maybe it would work but the main problem is when the user hovers over the element class "placiau", another table displays not hovered element's "aukciono_id". 我试图使用一个while循环来执行此操作,也许它可以工作,但是主要的问题是,当用户将鼠标悬停在元素类“ placiau”上时,另一个表未显示悬停的元素的“ a​​ukciono_id”。 I just cannot use while loop because while loop iterate through the query one by one. 我只是不能使用while循环,因为while循环一个遍历整个查询。 I have to identify every <td class="placiau"></td> "aukciono_id" somehow. 我必须以某种方式识别每个<td class="placiau"></td> “ aukciono_id”。 Also, the table should appear next to the hovered element but I will fix it by myself. 此外,该表应显示在悬停元素旁边,但我将自己修复它。


<table>
<?php
$aukciono_laimetojai_ir_aukciono_istorija_while = mysql_query("SELECT taw.id AS taw_id,
    tai.aukciono_id AS tai_aukciono_id, taw.user_id AS taw_user_id, taw.win AS taw_win,
    tai.date AS tai_date, taw.date AS taw_date, COALESCE(SUM(tai.bid), 0) AS tai_bid
FROM tb_auction_winners taw JOIN tb_aukciono_istorija tai
ON taw.id = tai.aukciono_id
WHERE tai.user_id = 206 GROUP BY aukciono_id");

$aukciono_istorija1_while = mysql_query("SELECT tab.id, tu.level, tab.user_id, tab.user,
    tab.bid, tab.date, tab.aukciono_id FROM tb_aukciono_istorija tab JOIN tb_users tu
ON tab.user_id = tu.id
WHERE tab.aukciono_id = 47 ORDER BY tab.id DESC");

while ($r1 = mysql_fetch_assoc($aukciono_laimetojai_ir_aukciono_istorija_while)) {
    if ($r1['taw_user_id'] == 206) { ?>
        <tr>
            <td><?php echo $r1['taw_date']; ?></td>
            <td><?php echo $r1['taw_win'] - $r1['tai_bid']; ?> Eur</td>
            <td>0 Eur</td>
            <td class="placiau">Plačiau <?php echo $r1['tai_aukciono_id']; ?></td>
        </tr>
<?php
    } else { ?>
            <tr>
                <td><?php echo $r1['tai_date']; ?></td>
                <td>0 Eur</td>
                <td><?php echo $r1['tai_bid']; ?> Eur</td>
                <td class="placiau">Plačiau <?php echo $r1['tai_aukciono_id']; ?></td>
            </tr>
<?php
    }
}
?>
</table>
<table id="aukciono_apzvalga" style="
width: 69.7%;
left: 632px;
position: absolute;
top: 590px;
z-index: 1;
opacity: 0;
-webkit-transition: opacity .5s ease-out;
transition: opacity .5s ease-out;
display: block;
overflow-y: auto;
max-height: 480px;">
<?php
    while ($r1 = mysql_fetch_assoc($aukciono_istorija1_while)) { ?>
        <tr>
            <td><?php echo $r1['aukciono_id']; ?></td>
        </tr>
<?php } ?>
</table>

<script>
    $('.placiau').hover(function() {
        $('#aukciono_apzvalga').css('opacity', 1);
    }, function() {
        $('#aukciono_apzvalga').css('opacity', 0);
    });
</script>

Picture how it looks like: 想象一下它的样子:

在此处输入图片说明 Note: 47 is just a random number as an example how it looks like 注意:47只是一个随机数,例如

When the user hovers "42", for example, it should show 42, instead of 47 in the other table and also in the "$aukciono_istorija1_while" query. 例如,当用户将鼠标悬停在 “ 42”上时,它应该在其他表以及“ $ aukciono_istorija1_while”查询中显示42,而不是47。 Is it possible to do so? 有可能这样做吗?

PS: I know, I should use mysqli_* or PDO instead of mysql_* PS:我知道,我应该使用mysqli_*PDO代替mysql_*

You have only one table generated by the loop, you should build all the possible tables inside the loop, and give each table a different id related to the aukciono_id , then in the on hover function, get the target aukciono_id and show the table related to this id. 循环仅生成一个表,应该在循环内构建所有可能的表,并为每个表指定与aukciono_id相关的不同ID,然后在on hover函数中获取目标aukciono_id并显示与这个编号。 try this: 尝试这个:

<?php

$aukciono_laimetojai_ir_aukciono_istorija_while = mysql_query("SELECT taw.id AS taw_id,
    tai.aukciono_id AS tai_aukciono_id, taw.user_id AS taw_user_id, taw.win AS taw_win,
    tai.date AS tai_date, taw.date AS taw_date, COALESCE(SUM(tai.bid), 0) AS tai_bid
    FROM tb_auction_winners taw JOIN tb_aukciono_istorija tai
    ON taw.id = tai.aukciono_id
    WHERE tai.user_id = 206 GROUP BY aukciono_id");

$aukciono_istorija1_while = mysql_query("SELECT tab.id, tu.level, tab.user_id, tab.user,
    tab.bid, tab.date, tab.aukciono_id FROM tb_aukciono_istorija tab JOIN tb_users tu
    ON tab.user_id = tu.id
    WHERE tab.aukciono_id = 47 ORDER BY tab.id DESC");

?>
<table>
<?php
while ($r1 = mysql_fetch_assoc($aukciono_laimetojai_ir_aukciono_istorija_while)) {
    if ($r1['taw_user_id'] == 206) { ?>
    <tr>
        <td><?php echo $r1['taw_date']; ?></td>
        <td><?php echo $r1['taw_win'] - $r1['tai_bid']; ?> Eur</td>
        <td>0 Eur</td>
        <td class="placiau" data-aukciono-id="<?php echo $r1['tai_aukciono_id']; ?>">Plačiau <?php echo $r1['tai_aukciono_id']; ?></td>
    </tr>
<?php
    } else { ?>
    <tr>
        <td><?php echo $r1['tai_date']; ?></td>
        <td>0 Eur</td>
        <td><?php echo $r1['tai_bid']; ?> Eur</td>
        <td class="placiau" data-aukciono-id="<?php echo $r1['tai_aukciono_id']; ?>">Plačiau <?php echo $r1['tai_aukciono_id']; ?></td>
    </tr>
<?php
    }
}
?>
</table>
<?php
    while ($r1 = mysql_fetch_assoc($aukciono_istorija1_while)) { ?>
<table class="aukciono_apzvalga" data-aukciono-id="<?php echo $r1['aukciono_id']; ?>" style="
    width: 69.7%;
    left: 632px;
    position: absolute;
    top: 590px;
    z-index: 1;
    opacity: 0;
    -webkit-transition: opacity .5s ease-out;
    transition: opacity .5s ease-out;
    display: block;
    overflow-y: auto;
    max-height: 480px;">
    <tr>
        <td><?php echo $r1['aukciono_id']; ?></td>
    </tr>
</table>
<?php } ?>
<script>
    $('.placiau').hover(function() {
        var aukciono_id = $(this).attr('data-aukciono-id');
        $('.aukciono_apzvalga[data-aukciono-id="'+aukciono_id+'"]').css('opacity', 1);
    }, function() {
        $('.aukciono_apzvalga').css('opacity', 0);
    });
</script>

Problem solved! 问题解决了! :) It was a bug in the while loop. :)这是while循环中的错误。

</table>
<?php
while ($r1 = mysql_fetch_assoc($aukciono_istorija1_while)) { ?>
<table class="aukciono_apzvalga" data-aukciono-id="<?php echo $r1['aukciono_id']; ?>" style="
width: 69.7%;
left: 632px;
position: absolute;
top: 590px;
z-index: 1;
opacity: 0;
display: block;
overflow-y: auto;
max-height: 480px;">
    <tr>
        <th colspan="5">Aukciono apžvalga</th>
    </tr>
    <tr>
        <th>Nr.</th>
        <th>Žaidėjas</th>
        <th>Lygis</th>
        <th>Suma</th>
        <th>Laikas</th>
    </tr>
<?php
    $i = mysql_num_rows($aukciono_istorija1_while);
    $apa = $r1['aukciono_id'];
    $aukciono_istorija2_while = mysql_query("SELECT tab.id, tu.level, tab.user_id, tab.user, tab.bid, tab.date, tab.aukciono_id FROM tb_aukciono_istorija tab JOIN tb_users tu ON tab.user_id = tu.id
    WHERE aukciono_id = $apa ORDER BY tab.id DESC LIMIT 10");
    while ($r2 = mysql_fetch_assoc($aukciono_istorija2_while)) { ?>
        <tr>
            <td><?php echo $r2['aukciono_id']; ?></td>
            <td><?php echo $r2['user']; ?></td>
            <td><?php echo $r2['level']; ?> lvl.</td>
            <td><?php echo $r2['bid']; ?> Eur</td>
            <td><?php echo date('H:i:s', strtotime($r2['date'])); ?></td>
        </tr>
<?php
        $i--;
    }
}
?>
</table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM