更新 這裏是我正在處理的代碼。我的代碼是使用PHP的Javascript。我是 ,讀取X,Y座標從MySQL數據庫中,然後能夠在 繪製矩形給出的位置。通過讀取X,Y座標畫平方
我在我的表座標中有3個字段:coordinate_id,x_coord,y_coord。它有5-6個 行。
在我的代碼中,我先用一個方塊進行測試,它可以工作。現在,我想通過使用多維數組遍歷 數據庫,以便繪製所有的矩形。
非常感謝!
的Javascript PHP:
<div class="section_a" >
<p>Section A</p>
<canvas id="imageView" width="600" height="500"></canvas>
<script type="text/javascript">
var ctx, cv;
cv = document.getElementById('imageView');
ctx = cv.getContext('2d');
ctx.lineWidth = 5;
ctx.strokeStyle = '#000000';
<?php
$select_coordinate_query = "SELECT * FROM coordinates";
$result = mysqli_query($conn,$select_coordinate_query);
//see if query is good
if($result === false) {
die(mysqli_error());
}
//array that will have number of desks in map area
while($row = mysqli_fetch_assoc($result)){
//get desk array count
//THIS IS WHERE I NEED HELP**
$desk = array(array("x" => $row['x_coord']),
array("y" => $row['y_coord'])
);
//x, y coordinates
$x_pos = $desk['x'];
$y_pos = $desk['y'];
//x,y width and height
$x_size = $x_pos + 40;
$y_size = $y_pos + 10;
//HELP**
?>
ctx.strokeRect(<?php echo "$desk[x]";?>, <?php echo "$desk[y]";?>,100 , 100);
<?
} //end while loop
?>
</script>
</div> <!-- end div section_a -->
所以..你尋求幫助如何來查詢mysql?如何從MySQL獲取數據到PHP?如何讓PHP來繪製你的圖表?你應該退後一步,看看更大的圖片 - 無所謂** WHERE **座標來自,他們只是座標,你需要編寫可以處理它們的繪圖代碼。數據庫本身並不在乎他們是座標。他們只是數字。 – 2014-09-25 14:23:29
也許嘗試使用svg來繪製您的廣場。您需要某種公式來計算每個方塊的大小,儘管 – Rasclatt 2014-09-25 14:25:59
對於遲到的回覆感到抱歉。不,我知道如何查詢和全部。我剛剛失去了。我發佈了我的代碼,現在我試圖使用多維數組來讀取表中的每個座標 – user3042226 2014-09-30 01:33:56