2014-05-03 65 views
0

我試圖從數據庫中顯示我的產品。我試圖用if 4%= 0來分割它,但是我不能讓它在一行中顯示4個項目。 請告訴我,我怎麼能做到這一點還是請大家給我提供任何其他的例子..如何從數據庫中連續顯示4條記錄

在此先感謝

她是我的代碼

<?php 

/**************MYSQL Connection*************************/ 
$con = mysql_connect("localhost","root",""); 
if (!$con) 
{ 
    die('Could not connect: ' . mysql_error()); 
} 
mysql_select_db("dogs_db", $con); 
/**************MYSQL Connection ENDS*************************/ 

    $split = 0; 
    $display_all = mysql_query("SELECT * FROM dogsinfo"); 
    ?> 
    <table> 
    <tr> 
    <?php 
while($fetch=mysql_fetch_assoc($display_all)) { 
$id = $fetch['id']; 
$dogname = $fetch['dogname']; 
?> 
<tr> 
    <td><label><?php echo $i; ?></label></td> 
    <td><label><a href="details.php?id= 
<?php echo $fetch["id"];?>&tablename=<?php echo "dogsinfo"; ?>"> 
<img src="admin/uploads/<?php echo $fetch["file_name"]; ?>" alt=" 
<?php echo $fetch["file_name"]; ?>" 
title="<?php echo $fetch["file_name"]; ?>" height="100" width="100" /> 
</a></label></td> 
<tr> 
<td>DogName:</td>       
    <td><label><?php echo $fetch["dogname"];?>   </label>  
</td> 
</tr> 
</tr> 
    <?php 
    $split++; 
if ($split%4==0){ 
    echo '</tr><tr>'; 
    } 
} 
?> 
</tr> 
</table> 

請回復.......

回答

0
SELECT * FROM `dogsinfo` LIMIT 4 

這將顯示數據庫中的前4條記錄。

0

使用此

$sql="SELECT * FROM products WHERE ProductCatId = 1 ORDER BY `ProductCatId` ASC LIMIT 0 , 4"; 

中,你可以把願望沒有與位置記錄..

一樣,如果你想看到的5,6,7,8記錄,則只是簡單地使用

$sql="SELECT * FROM products WHERE ProductCatId = 1 ORDER BY `ProductCatId` ASC LIMIT 4 , 4"; 

第一沒有被position..and第二是沒有多少沒有你想..希望這會有所幫助.. :)

編輯1:對不起,我使用的例子..你可以改變變量名.. :)

編輯2:請我這個代碼

$sql="SELECT * FROM products WHERE ProductCatId = 1 ORDER BY `ProductCatId` ASC LIMIT 0 , 4"; 
$Result = mysql_query($sql); 

// $sql="SELECT * FROM products WHERE ProductCatId = 1 ORDER BY `ProductCatId` ASC LIMIT 4 , 4"; 
// $Result = mysql_query($sql); 

// $sql="SELECT * FROM products WHERE ProductCatId = 1 ORDER BY `ProductCatId` ASC LIMIT 8 , 4"; 
// $Result = mysql_query($sql); 

// $sql="SELECT * FROM products WHERE ProductCatId = 1 ORDER BY `ProductCatId` ASC LIMIT 12 , 4"; 
// $Result = mysql_query($sql); 

// $sql="SELECT * FROM products WHERE ProductCatId = 1 ORDER BY `ProductCatId` ASC LIMIT 16 , 4"; 
// $Result = mysql_query($sql); 

?> 
<div class="PageContent"> 
<?php while($list = mysql_fetch_array($Result)) 
{ ?> 
    <div class=""> 
     <?php { ?> 
     <div class="InnerDiv"><?php echo $list['ProductName'];?> 
      <div class="ImageDiv"> 
      <center> 
       <img src="<?php echo CAT_IMAGE_URL.$list['ProductImage'];?>" width="120px" height="180"/> 
      </center> 
      </div> 
      <center> 
      <div class="a2">Price</div> 
      </center> 
     </div> 
     <?php }?> 
    </div> 
    <?php }?> 
</div> 

有想法,這裏是一個小白的想法(對不起,那)您可以運行5個SQL查詢,然後根據您的需要和您的訂單顯示它們。

+0

我想以下面的方式顯示總記錄................. image-1 image-2 image3 image-4 .....像這樣...考慮我在我的數據庫中有20條記錄,那麼它應該顯示在5行4條記錄在每一行........ ...... – Pavan

+0

嘿pavan m wrking解決你的問題,直到那時你可以得到這個我的想法..因爲它不好的bt它會有所幫助,你可以使用list1 list2 list3等..hope我幫助..並相信我在這也很難wrking .. :) –

相關問題