I've been looking around and have noticed there are a lot of different ways to extract data from a database query. I'm just trying to get an understanding as to what is the right and/or best approach (secure/efficient that sort of thing). I'm sure there are other methods to add below, but would like to know of the options below which is best.
This is how I've currently been doing it (Keep in mind that I've abbreviated the code so you can get the basic idea.):
<?php
$query = "SELECT company_id, company_name, company_address FROM company";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
$company_id= $row["company_id"];
$company_name = $row["company_name"];
$company_address = $row["company_address"];
etc..
?>
<li><a href="#"><?php echo $company_name; ?></a></li>
<?
/*** end the loop ***/
}
?>
Another method I've seen using the same query is to not assign the variables and just output the html like:
<li><a href="#"><?php echo $row['company_name']; ?></a></li>
Yet, another method I've seen using extract:
<?php
$query = "SELECT company_id, company_name, company_address FROM company";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
extract($row);
?>
Output html as:
<li><a href="#"><?php echo $company_name; ?></a></li>
Any insight is greatly appreciated. Thanks.