2017-04-12 38 views
-2

所以我想從我的數據庫中回顯一些數據。從mySQL數據庫將數據回顯到3x3網格

<?php 

     $connect = mysql_connect('xxxxx', 'xxxxx', 'xxxxx'); 
     mysql_select_db("xxxxx", $connect) or die(mysql_error()); 

     $lsql = "SELECT * FROM xxxxxxx ORDER BY Value DESC LIMIT 6"; 

     $lquery = mysql_query($lsql) or die(mysql_error()); 


     while ($lrow = mysql_fetch_array($lquery)) 
      $lrows[] = $lrow; 

       foreach ($lrows as $lrow){ 
         $ProperBrand = $lrow['ProperBrand']; 
         $LowerBrand = $lrow['LowerBrand']; 
         $PageTitle = $lrow['PageTitle']; 
         $PageH1 = $lrow['PageH1']; 
         $PageExcerpt = $lrow['PageExcerpt']; 
         $ContentP1 = $lrow['ContentP1']; 
         $ContentP2 = $lrow['ContentP2']; 
         $Image1 = $lrow['Image1']; 
         $Image2 = $lrow['Image2']; 
         $Image3 = $lrow['Image3']; 
         $BrandURL = $lrow['BrandURL']; 

        echo (' 
        <div class="col-sm-2"> 
        <img src="'. $Image1 .'" class="top-images-larger"> 
        </div> 
           '); 



        } 
    ?> 

我可以附和它像上面那將正常工作,但我似乎無法弄清楚如何我將能夠與一個結構化的自舉行做到這一點。我想有一個9格上移動3×3的和已經做了類似下面的:

<div class="row visible-xs" align="center"> 
    <div class="col-sm-4 padding-bottom"> 
     <img src="/images/brandlogos/logo.png" class="top-images"> 
     <img src="/images/brandlogos/logo.png" class="top-images"> 
     <img src="/images/brandlogos/logo.png" class="top-images"> 
    </div> 
    <div class="col-sm-4 padding-bottom"> 
     <img src="/images/brandlogos/logo.png" class="top-images"> 
     <img src="/images/brandlogos/logo.png" class="top-images"> 
     <img src="/images/brandlogos/logo.png" class="top-images"> 
    </div> 
    <div class="col-sm-4 padding-bottom"> 
     <img src="/images/brandlogos/logo.png" class="top-images"> 
     <img src="/images/brandlogos/logo.png" class="top-images"> 
     <img src="/images/brandlogos/logo.png" class="top-images"> 
    </div> 
    <div class="visible-xs col-sm-4 spacer-t"> 
     <button type="button" class="btn btn-success btn-block">View All Stores</button> 
    </div> 
</div> 

如果我是爲了呼應就像我在上面的例子中都做到了將打破這種「網格」的結構。

在此先感謝。

+3

爲什麼你使用一個不推薦的mysql api而不是mysqli或pdo與一個預先準備的語句,用戶輸入是否應該是圖片的一部分? –

+2

你需要養成[接受答案](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)的習慣,它可以幫助你解決你的問題。您將獲得積分,其他人將被鼓勵幫助您。 –

+1

**警告**:如果您只是學習PHP,請不要學習過時的['mysql_query'](http://php.net/manual/en/function.mysql-query.php)界面。這很糟糕,並且已經在PHP 7中被刪除了。像[PDO不是很難學的東西](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-php-pdo- for-database-access /)以及[PHP The Right Way](http://www.phptherightway.com/)等指南有助於解釋最佳實踐。確保**你的用戶參數[妥善轉義](http://bobby-tables.com/php),否則你將以嚴重的[SQL注入漏洞](http://bobby-tables.com/ )。 – tadman

回答

0

你好,你可以使用回聲與HTML表中顯示一個網格:

<?php 
    echo "<table> 
      <tr> 
      <th>column1</th> 
      <th>column2</th> 
      <th>column3</th> 
      </tr> 
      <tr> 
      <td>".$lrow['yourdata']."</td> 
      <td>".$lrow['yourdata2']."</td> 
      <td>".$lrow['yourdata3']."</td> 
      </tr> 
     </table>"; 
?> 

希望我幫助!

+0

嘿,但如果有9個塊,它會使用上面給出的例子回顯3個表格? –