Öncelikle, uzun soru ... ama bu herhangi bir yardım kafama yapıyor özür minnetle kabul edilecektir.
Ben mysql veritabanından veri döndürmek için aşağıdaki işlevi yazdık:
function injuryTable()
{
# get all players that are injured and their injuires...
$sql = "SELECT players.id, players.injury_id, players.pname, injuries_date.name, start_date, end_date
FROM players INNER JOIN injuries_date
ON injury_id = injuries_date.id";
$result = sqlQuery($sql);
return $result;
}
Aşağıdaki gibi sqlquery fonksiyonu:
function sqlQuery($sql)
{
$products = array();
$link = dbConnect('localhost', 'root', '', 'umarrr');
$result = mysqli_query($link, $sql);
while ($row = mysqli_fetch_array($result))
{
$products[] = $row;
}
# return each row:
return $products;
#mysqli_close($link);
}
It's all connected to the database, and everything works fine. However when I try to iterate through the results: it only returns one row:
$injury_table = injuryTable();
// make it more readable:
foreach ($injury_table as $table);
{
echo $table['pname'];
echo $table['name'];
echo $table['start_date'];
echo $table['end_date'];
}
Yukarıda yazdığım sql deyimi MySQL sorgu tarayıcıda mükemmel çalışır, bu yüzden herkes burada sorunun ne olabileceğini biliyor?
print_r($injury_table)
Çıktı
Array ( [0] => Array ( [0] => 1 [id] => 1 [1] => 6 [injury_id] => 6 [2] => person [pname] => person [3] => wrist [name] => wrist [4] => 2008-11-21 [start_date] => 2008-11-21 [5] => 2010-11-11 [end_date] => 2010-11-11 ) [1] => Array ( [0] => 2 [id] => 2 [1] => 5 [injury_id] => 5 [2] => woman [pname] => woman [3] => neck [name] => neck [4] => 2009-11-12 [start_date] => 2009-11-12 [5] => 2010-09-09 [end_date] => 2010-09-09 ) [2] => Array ( [0] => 3 [id] => 3 [1] => 4 [injury_id] => 4 [2] => girl [pname] => girl [3] => groin [name] => groin [4] => 2010-11-27 [start_date] => 2010-11-27 [5] => 2010-12-01 [end_date] => 2010-12-01 ) [3] => Array ( [0] => 4 [id] => 4 [1] => 1 [injury_id] => 1 [2] => boy [pname] => boy [3] => achilles [name] => achilles [4] => 2010-02-01 [start_date] => 2010-02-01 [5] => 2010-03-23 [end_date] => 2010-03-23 ) [4] => Array ( [0] => 5 [id] => 5 [1] => 2 [injury_id] => 2 [2] => man [pname] => man [3] => toe [name] => toe [4] => 2010-01-01 [start_date] => 2010-01-01 [5] => 2010-02-02 [end_date] => 2010-02-02 ) )