[PHP] [Mysql]选择并显示简单

#GET from Mysql
$select = "SELECT content from content WHERE page = 'index';";
$result = mysql_query($select);
$row = mysql_fetch_row($result);

#Show in diferent places in my page
<?PHP echo $row[0]; ?>
<?PHP echo $row[1]; ?>

I'm using this code above, the problem is: It's showing only the first result. What did I wrong?

$select = "SELECT content from content WHERE page = 'index';";
$result = mysql_query($select);

//$row = mysql_fetch_row($result); 
// mysql_fetch_row() fetches ONLY ONE ROW

// If you want to fetch them all, yes, you must use a loop.
while ($row = mysql_fetch_row($result)) {
    $rows[] = $row;
}
// So do this, get all the rows, and then you can use them in different places in your page

// Show in diferent places in your page
<?PHP echo $rows[0][0]; ?>
<?PHP echo $rows[1][0]; ?>

It's better to do this in a for loop - that way it will get all the results each time, rather than hardcoding for a scenario with just two results, etc.

<?php
$select = "SELECT content from content WHERE page = 'index';";
$result = mysql_query($select);
$rows = mysql_fetch_assoc($select);

foreach ($rows as $row) {
    echo $row['content']; // associative array with strings for keys
}
?>

Also, you should be using mysqli for security reasons.