简体   繁体   English

在while循环中的SQL查询中调用SQL查询

[英]Calling an SQL query inside an SQL query while loop

<?
$id = ($_GET["id"]);
$query = mysql_query("SELECT * FROM champions WHERE id=$id") or die("Error: " .       mysql_error());

while($row = mysql_fetch_array($query)){
$name = $row[1];
$icon = $row[2];
$picon = $row[4];
$passive = $row[5];
$qicon = $row[6];
$qskill = $row[7];
$wicon = $row[8];
$wskill = $row[9];
$eicon = $row[10];
$eskill = $row[11];
$ricon = $row[12];
$rskill = $row[13];
$ad = $row[14];
$as = $row[15];
$arm = $row[16];
$mr = $row[17];
$mov = $row[18];
$hp = $row[19];
$mana = $row[20]; 


$secquery = mysql_query("SELECT * FROM icons WHERE picid=1") or die("Error: " .    mysql_error());
while($row = mysql_fetch_array($secquery)){

$hpicon = $row[1];
$manaicon = $row[2];

echo '<div class="container-fluid">';
echo '<div class="row-fluid">';
echo '<div class="span6">';
echo '<table id="noborder">';
echo '<tr>';
echo '<td><img src="data:image/png;base64,' . base64_encode($icon) . '" /></td>';
echo '<td>' . $name . '</td>';  
echo '</tr>';
echo '</table>';
echo '</div>';
}

echo '<div class="span6">';
echo '<table id="noborder" >';
echo '<tr><td id="celltop" width="64px"><img src="data:image/png;base64,' .    base64_encode($picon) . '" /> </td><td>' . $passive . '</td></tr>';
echo '<tr><td id="celltop" width="64px"><img src="data:image/png;base64,' . base64_encode($qicon) . '" /> </td><td>' . $qskill . '</td></tr>';
echo '<tr><td id="celltop" width="64px"><img src="data:image/png;base64,' . base64_encode($wicon) . '" /> </td><td>' . $wskill . '</td></tr>';
echo '<tr><td id="celltop" width="64px"><img src="data:image/png;base64,' . base64_encode($eicon) . '" /> </td><td>' . $eskill . '</td></tr>';
echo '<tr><td id="celltop" width="64px"><img src="data:image/png;base64,' . base64_encode($ricon) . '" /> </td><td>' . $rskill . '</td></tr>';
echo '</table>';
echo '</div>';    

} }

?>

I have a 117 different pages. 我有117个不同的页面。 What I'm trying to do is call icons from a separate table which will be the same for all 117 pages, that's why I've stored them in a different table. 我想做的是从一个单独的表中调用图标,这对于所有117页来说都是相同的,这就是为什么我将它们存储在另一个表中的原因。 But I need to call the icons among the data from the other table. 但是我需要在另一个表的数据中调用图标。

even if you get this working this many hits on your database is a bad idea and will be very slow I would re engineer this to only hit the database once or at most twice to get all the values you need 即使您可以执行此操作,对数据库的如此多的命中也是一个坏主意,而且非常慢,我将对其进行重新设计,使其仅一次或最多两次命中数据库即可获得所需的所有值

Possible ideas 可能的想法

OPT A write view that contains everything you need joint originally from the icons table then to the champions table either duplicating the champions for each icon then just create a couple of loops OPT包含您需要的所有内容的写视图,最初是从图标表连接到冠军表,或者是复制每个图标的冠军,然后仅创建几个循环

OPT B get all the icons then and pop them in a class structure to then retrieve as you need them from memory rather than per record. 然后,OPT B获取所有图标,并将它们弹出到类结构中,然后根据需要从内存而不是按记录进行检索。

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

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