PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
mysql_connect ('local', 'name', 'pass') or die ('Error connecting to mysql');
mysql_select_db (db);
$name = $_GET['name'];
$query = "SELECT * FROM job WHERE lname='$name' ORDER BY id desc";
$result = mysql_query($query);
mysql_query($query) or die ('cannot retrieve');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo $row['company'];
}
mysql_free_result($result);
?>
you have two fetch requests. One before the loop, one as the conditional of the loop. If your query only returns a single record, you'll destroy the results.
$query = "SELECT company FROM job WHERE lname='$name' ORDER BY id desc";
$result = mysql_query($query);
mysql_query($query) or die ('cannot retrieve');
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo $row['company'];