Im struggling with PHP to get data from a mysql db and put it in to PHP arrays in a way thats actually easy to use.
Assume I have a table "miners'" with the following fields:
ip (also primary key)
name
status
location
...
I want to fetch this from mysql, put in an array and then loop through all miners, in this example just to display the ip and names.
The best Ive come up with is this:
$query = "SELECT * FROM miners";
$result = mysql_query($query) or die(mysql_error());
$i=0;
while ($r = mysql_fetch_assoc($result)) {
$miner[$i]=$r;
$i++;
}
foreach ($miner as $i=>$d) {
echo "miner : ". $d["ip"] ." ". $d["name"] .$d["whateverotherfield"];
}
I does work, but its such a kludge.
Im sure there is a better way, but I just dont see it.
Any help appreciated.