 |
""""""""""""""ถาม code select จากฐานข้อมูลเพื่อเข้า array""""""""""" |
|
 |
|
|
 |
 |
|
$matrixWidth = 10;
// $points is an array in the following format: (router1,router2,distance-between-them)
$points = array(
array(1,3,7),
array(1,2,1),
array(2,3,1),
array(3,8,2),
array(8,5,12),
array(5,4,22),
array(3,4,24),
array(4,9,21),
array(3,4,25),
array(3,10,24)
);
$ourMap = array();
// Read in the points and push them into the map
for ($i=0,$m=count($points); $i<$m; $i++) {
$x = $points[$i][0];
$y = $points[$i][1];
$c = $points[$i][2];
$ourMap[$x][$y] = $c;
$ourMap[$y][$x] = $c;
}
Tag : PHP, MySQL, jQuery
|
|
 |
 |
 |
 |
Date :
2010-08-04 21:59:27 |
By :
wisan191 |
View :
1144 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

สมมุติเรามีฐานข้อมูลแบบนี้เราจะ select ข้อมูลออกมายังไงเพื่อให้เก็บอยู่ใน array และเข้าลูป for ได้
โดย find station_id คือ ต้นทาง
และ find ststion_id2 คือ ปลายทาง
และ distance คือค่าระยะทาง
เราจะ select ออกมายังไงครับ ขอความช่วยเหลือด้วย
|
 |
 |
 |
 |
Date :
2010-08-04 22:08:55 |
By :
wisan191 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$points = array();
while ($row = mysql_fetch_assoc())
{
$points[] = array($row['station_id'], $row['station_id2'], $row['distance']);
}
http://gunner.freetzi.com
|
 |
 |
 |
 |
Date :
2010-08-04 22:14:38 |
By :
pjgunner |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$sql="SELECT * FROM `$table`;";
$query=mysql_query($sql);
$num_row=mysql_num_rows($query);
while($items=mysql_fetch_array($query)){
$id[]=$items[busstop_id];
$station1[]=$items[station_id];
$station2[]=$items[station_id2];
$distance[]=$items[distance];
}
for($row=0;$row<$num_row;$row++){
echo $id;
echo $station1;
echo $station2;
echo $distance;
}
|
 |
 |
 |
 |
Date :
2010-08-04 22:24:12 |
By :
aunjijoke |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อิ อิ อยากมีส่วนร่วม
<?php
$points = array();
while ($row = mysql_fetch_assoc()) {
$points[] = array(
$row['station_id'],
$row['station_id2'],
$row['distance']
);
}
?>
|
 |
 |
 |
 |
Date :
2010-08-04 23:19:33 |
By :
DS_Ohm |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|