PHP同时循环不同的图像

时间:2016-01-26 20:53:28

标签: php html while-loop

好的,让我澄清一切。

Chars表格看起来像http://prntscr.com/9v8jiv

这是标准的html

<div id="characterone">
  <h1 class="charactername">Test_Name</h1>
  <p class="characterstats">DOB: 12/01/1992</p>
  <p class="characterstats">Origin: Mexican</p>
  <p class="characterstats">Time in Los Santos: 56</p>

  <button class="choosebutton">Choose</button>
</div>

<div id="charactertwo">
   <h1 class="charactername">Angelo_Damce</h1>
   <p class="characterstats">DOB: 12/01/1992</p>
   <p class="characterstats">Origin: American</p>
   <p class="characterstats">Time in Los Santos: 26</p>

   <button class="choosebutton">Choose</button>
</div>

<div id="characterthree">
    <h1 class="charactername">Moemen_Walid</h1>
    <p class="characterstats">DOB: 12/01/1992</p>
    <p class="characterstats">Origin: American</p>
    <p class="characterstats">Time in Los Santos: 26</p>

    <button class="choosebutton">Choose</button>
</div>

我想做的就是,选择某人登录的角色,然后他在他面前看到3,然后他选择,

我开始正常查询它们

$getchars = mysqli_query($con,"SELECT * FROM `characters` where Username = '".$user."'") or die('Error: ' . mysqli_error($con));
    $check = mysqli_num_rows($getchars);

现在我需要找到一种方法,以便mysql查询找到的每个char,在html中回显或编写。

例如:echo&#39;&#39;。$ row [1] [&#34;姓名&#34;]。&#39; &#39 ;; 但在每个div中应该有一个不同的回声

'.$row[2]["Name"].'
^ But of course this code isn't real. just trying to explain.

2 个答案:

答案 0 :(得分:0)

只需使用计数器

 <?php if(!is_null($manufacturer->getMenufecturerName())): ?>
 <div class="manufacturer-name">
 <?php 
   echo Mage::getModel('eav/entity_attribute_source_table')
   ->setAttribute(Mage::getModel('eav/entity_attribute')
   ->load(Mage::getModel('eav/entity_attribute')
   ->getIdByCode('catalog_product',"manufacturer")))
   ->getOptionText($manufacturer->getMenufecturerName())
 ?>
 </div>
 <?php endif; ?>

答案 1 :(得分:0)

Ok这是您问题的完整答案。只需使用数据库中正确的列名替换名称和时间列名称。

$i = 1;
while($rowget = mysqli_fetch_array($getchars))
        {
            $id1 = 'characterone';
            $id2 = 'charactertwo';
            $id3 = 'characterthree';
            if($i<4){
               echo'<div id="'.${'id'.$i}.'">';
               echo '<h1 class="charactername">'.$rowchar["Name"].'</h1>
              <p class="characterstats">DOB: '.$rowchar["Birthdate"].'</p>
              <p class="characterstats">Origin: '.$rowchar["Origin"].'</p>
              <p class="characterstats">Time in Los Santos: '.$rowchar["Skin"].'</p>            
              <button class="choosebutton">Choose</button>';
               echo '</div>';
            }
$i++;
}