我正在尝试转移&#34; aukciono_id&#34;从一张桌子到另一张桌子。我试图用一个while循环来做它也许它会起作用但主要的问题是当用户悬停而不是元素类&#34; placiau&#34;时,另一个表显示不<强势>徘徊元素&#34; aukciono_id&#34;。我只是不能使用while循环,因为while循环逐个遍历查询。我必须确定每个<td class="placiau"></td>
&#34; aukciono_id&#34;不知何故。此外,该表应显示在悬停元素旁边,但我会自行修复。
<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>
想象它的样子:
例如,当用户悬停&#34; 42&#34;时,它应显示42,而不是另一个表中的47,以及&#34; $ aukciono_istorija1_while&#34 ;查询。是否可以这样做?
PS:我知道,我应该使用mysqli_*
或PDO
代替mysql_*
答案 0 :(得分:1)
你只有一个循环生成的表,你应该在循环中构建所有可能的表,并给每个表一个与aukciono_id
相关的不同的id,然后在on hover函数中,获取目标aukciono_id
并显示与此ID相关的表格。
试试这个:
<?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>
答案 1 :(得分:0)
问题解决了! :)这是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>