Bu konuda size yardımcı olabilir kılavuzda örnek bir çift vardır; Örneğin, manuel sayfasında mysql_query
(quoting, and adapting a bit),
Önce sorgu yürütmek zorunda:
$result = mysql_query('SELECT * from mytable');
if (!$result) {
die('Invalid query: ' . mysql_error());
}
Note that dying in case of an error, and echoing the error-message, is OK while developping -- but you shouldn't do that in a production environment !
And, then, you have to loop over the lines of results, fetching them one at a time :
while ($row = mysql_fetch_assoc($result)) {
// Use the data in $row
}
And, inside this loop, as $row
is an array, you can iterate over its content with a foreach
loop :
foreach ($row as $name => $value) {
echo "column $name contains $value<br />";
}
Note : at this point, you should really invest some time going through a couple of sections of the PHP manual : it will take some time, yes ; but it will definitely help you, and will not be wasted time :-)