I am trying to get my head around object oriented PHP. I'm working from an example in the 2009 version of PHP and MySQL web development book, but where they start out with the example using search input I am just calling straight to the database without a user search query.
1) I am not 100% sure what the lines starting with $result are doing. Can someone explain each line--well in particular why -> does in each instance and how $i works (What is $i? and why would I choose to use it).
2) I am doing something wrong with the bit starting
for ($i=0; $i <$num_results; $i++) {
as the number of results displays correctly when I use the $num_results echo statement but only one row of from the database displays for the increment bit of the code.
Thanks for your help
<?php require_once('Connections/connectionname.php');
$db->select_db(databasename);
$query = "SELECT * FROM distance";
$result = $db->query($query);
$num_results = $result->num_rows;
echo"<br />Number of locations: ".$num_results."</p>";
for ($i=0; $i <$num_results; $i++) {
//process results
}
$row = $result->fetch_assoc();
echo"<p.>".($i+1).". Miles: ";
echo ($row['miles']);
echo"<br />Location: ";
echo stripslashes($row['location']);
?>
<?php
mysql_free_result($distance);
?>