2015-12-09 144 views
0

我使用此代碼從我的數據庫中檢索一些數據。該數據庫有一列,它們是從0到40的數字。我從DIV標記中的數據庫中獲取我的返回數字。從數據庫填充返回值

1 - 20在div標籤的左側 21 - 40在div標籤的右側 0正在div的中間位置標籤

我想如果有可能把填充一些特定的數字,或者哪種方式是最聰明的做呢?

編輯...

感謝您的答案傢伙。代碼非常業餘,但我還不是很擅長。但是數據庫的返回是可以的,除非每次都有一個0。在div中的數字所在的左側,這是我想要填充某些特定數字的位置。

我希望能夠明白我的問題一點點?

問候 朱莉

enter image description here

HTML:

<html> 

<head> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
    <script src="js/my_script.js" type="text/javascript"></script> 
    <link rel="stylesheet" type="text/css" href="css\placing.css"> 
    <title>Numbers</title> 
</head> 

<body> 
    <div class="topbar"> 
     <p>Topbar</p> 
    </div> 
    <div class="talraekke" id="show"> 
     <p>Tal</p> 
    </div> 
     <div class="content"> 
     <p>Enter The Number</p> 
     <form id="myForm" action="select.php" method="post"> 
      <input type="number" name="numbervalue"> 
      <button id="sub">Save</button> 
     </form> 
     <span id="result"></span> 
    </div> 
    <div class="talraekke"> 
     <p>test</p> 
    </div> 
    <div class="talraekke"> 
     <p>test</p> 
    </div> 


</body> 
</html> 

JS:從DB

// Insert function for number 
function clearInput() { 
    $("#myForm :input").each(function() { 
     $(this).val(''); 
    }); 
} 

    $(document).ready(function(){ 
     $("#sub").click(function(e) { 
     e.preventDefault(); // remove default action(submitting the form) 
     $.post($("#myForm").attr("action"), 
     $("#myForm :input").serializeArray(), 
     function(info){ $("#result").html(info); 
     }); 
     clearInput(); 
    }); 
    }) 


// Recieve data from database 
$(document).ready(function() { 
      setInterval(function() { 
       $('#show').load('response.php') 
      }, 3000); 
     }); 

PHP響應

// Return data from database 
$result = $conn->query("SELECT numbers FROM numbertable"); 
if ($result->num_rows > 0) { 
    while ($row = $result->fetch_assoc()) { 
     echo $row['numbers'] . '<br>'; 
    } 
+0

你是從你的Ajax調用得到正確的結果看起來有點奇怪的代碼給我。如果我錯了,並且一切都適合您,請在您想要輸出數據的地方張貼您的HTML。 – Franco

+0

你好佛朗哥。非常感謝您的回答。我剛剛編輯了我的問題。也許現在更清楚了?最好的問候 – Julie24

回答

0

我的理解,你應該使用這個簡單的方法:

<?php 

for($i=0; $i<=40; $i++) 
{ 
    echo '<div class="test">'.$i.'</div></br>'; 
} 

?> 
<style type="text/css"> 
.test{ 
background-color:#284062; 
text-align:center; 
color:#fff; 
min-width:30px; 
width:32px; 
} 
</style> 
+0

我認爲,朱莉希望得到的輸出在列和特定的順序 – Franco

+0

謝謝你的答案Herolind。是的,那就是我的意思佛朗哥。 – Julie24