I am trying to echo this info with the different rows in the database but when I try the following code only the first result shows up. Please can someone help

$con = mysql_connect("localhost","blar","blar");
if (!$con)
  die('Could not connect: ' . mysql_error());

mysql_select_db("blar", $con);

$result = mysql_query("SELECT * FROM TABLE") or trigger_error(mysql_error().$sql);
$row = mysql_fetch_array($result); {
echo '<ul class="feature-list-smaller">
                <a href="#" class="icon"><img src="image.png" width="52" height="52" alt="" /></a>
                <div class="text">
                    <h4><a href="'. $row['Link'].'-contract.php">'. $row['Make'].' '. $row['Model'].'</a></h4>
echo "/n";

Hope someone can help. Thanks in advance

Member Avatar

Yes, well it will unless you use a loop. Try

while($row = mysql_fetch_array($result)){

thanks for both of your help, Its now works :)

Member Avatar

BTW: Adam's is better if you're not using column numbers to reference your fields, which I assume you're not. The *_array() function returns an index-based array AND an associative array, whereas the *_assoc() just returns the associative array. For a good look, print out the result with something like print_r($row).

If solved, please mark it so.

Hi Sorry, now i have a problem with this, if you can help please

fields have spaces in the fields being echoed, how would I use the replace to change those spaces to a dash.

Make field will be something like blar blar blar and I need it to be blar-blar-blar

<h4><a href="">'. $row['Make'].'</a></h4>

Hope you can help again. Thanks

Member Avatar
echo '<h4><a href="">'. str_replace(' ','-',trim($row['Make'])) . '</a></h4>';
Member Avatar


I think he double post this. You gave the correct answer for this post and the other post