简体   繁体   English

使用php以ul和li格式显示来自mysql的记录

[英]displaying records from mysql in ul and li format with php

i want to display the mysql's fetched results with php and html in unordered list and list format as like http://www.miniclip.com/games/en/ . 我想用无序列表和列表格式显示mysql的获取结果,如php和html,如http://www.miniclip.com/games/en/ you can see in the all games categories in the footer in alphabetical order. 您可以按字母顺序在页脚中的所有游戏类别中查看。 the same requirement i do have. 我有同样的要求。 i guess i have written the logic its working fine. 我想我写的逻辑工作正常。 but i am unable to represent it properly. 但我无法正确代表它。 you can see in the following link above the footer. 您可以在页脚上方的以下链接中看到。 http://www.playtoongames.com/play1 ... http://www.playtoongames.com/play1 ...

code: 码:

<?php
$gameQuery = mysql_query ("SELECT name, LEFT(name, 1) AS first_char FROM games WHERE UPPER(name) BETWEEN 'A' AND 'Z' OR name BETWEEN '0' AND '9' ORDER BY name");
$current_char = '';
   while ($gameRow = mysql_fetch_assoc($gameQuery)){
     if ($_SESSION['lang'] == 'fr'){
         $description = $gameRow['description_fr'];
     }else{
   $description = $gameRow['description'];
 }
?>

<div style='float:left' title="<img src='<?php echo $gameRow['sitePath'];?>games/images/<?php echo $gameRow['img_100x75'];?>' width='230' height='112' class='thumb' alt='<?php echo $gameRow['name'];?>'/>" class='tooltip'>

                     <ul>
                     <li>
     <a href='<?php echo $gameRow['sitePath'];?>play/<?php echo str_replace(' ','_',$gameRow['name']);?>'><?php echo $gameRow['name'];?></a>
                     </li> 
                      </ul>
</div>

can anybody look into this... 任何人都可以看看这个......

Regards, sam. 问候,山姆。

On the Playtoons site, each <li> is in its' own individual <ul> - this means you're creating a new list for each item: 在Playtoons网站上,每个<li>都在其自己的个人<ul> - 这意味着您要为每个项目创建一个新列表:

<ul>
  <li>13 More Days</li>
</ul>
<ul>
  <li>A Bikers Heaven</li>
</ul>

What you should be doing is using one <ul> which contains all the items as <li> s: 你应该做的是使用一个<ul> ,它包含所有项目<li> s:

<ul>
  <li>13 More Days</li>
  <li>A Bikers Heaven</li>
</ul>

Well, I think the key is that there are 6 columns, which just means you'll need to break your array into 6 different parts. 好吧,我认为关键是有6列,这意味着你需要将你的阵列分成6个不同的部分。

Here's some psuedocode: 这是一些伪代码:

$pArr = $from_sql_array; // I'll let you take care of that.
$itmCount = count($pArr);
$itmsPerCol = ceil($itmCount / 6.0);
for ($ii=0; $ii < 6; $ii++)
{
  $pCol = array_slice($pArr, $itmsPerCol * $ii, $itmsPerCol);
  echo '<ul class="floatleft"><li>'.implode("</li>\n<li>",$pCol).'</li></ul>';
}

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

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