Step 1:
Create a connection and assign it to a variable (mysql_pconnect).
<?php
$host = 'localhost:8888';
$username = 'root';
$password = 'root';
$connection = mysql_pconnect($host, $username, $password);
?>
Step 2:
Select the database (mysql_select_db).
<?php
$database = 'lessons';
mysql_select_db($database, $connection);
?>
Step 3:
Create a Query String assigned to a variable.
<?php
$myQuery ='SELECT * FROM restaurants';
?>
Step 4:
Query the database with that string (mysql_query).
<?php
$result = mysql_query($myQuery,$connection);
?>
Step 5:
Convert to Associative Array for ease of use (mysql_fetch_assoc).
<?php
$result_assoc = mysql_fetch_assoc($result);
?>
Step 6:
Echo Results (assoc variable and column name).
<?php
echo $result_assoc['restTitle'];
?>
Step 7:
Loop all results (do while : mysql_fetch_assoc).
<?php do { ?>
<h4><?php echo $result_assoc['restTitle']; ?></h4>
<ul>
<li><strong>restID (primary key):</strong><?php echo $result_assoc['restID']; ?></li>
<li><strong>Type:</strong><?php echo $result_assoc['restType']; ?></li>
<li><strong>Link:</strong><?php echo $result_assoc['restLink']; ?></li>
<li><strong>Review:</strong><?php echo $result_assoc['restReview']; ?></li>
</ul>
<?php } while ( $result_assoc = mysql_fetch_assoc($result) );?>
Revise Step 3:
You can be as specific as you like with the query string.
$myQuery ='SELECT restLink, restTitle FROM restaurants'; sets specific columns
WHERE and AND add to conditional results - so limiting the resulting records (rows)
ORDER BY refers to sort order by column name either ascending (ASC), or decending (DESC)
<?php
$myQuery ="SELECT * FROM restaurants
WHERE restID >= 6
ORDER BY restTitle ASC";
?>
NOTE:
You may need to turn display_errors ON in the php.ini file in the htdocs/config/php5 folder. Refresh MAMP by stopping servers then starting them again.