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
//build our query
mysql_connect('localhost', 'homtek_dclamp', 'my_password');
mysql_select_db('homtek_homtek');
$query = mysql_query("SELECT * `news`");
//loop through each record
while($array = mysql_fetch_array($query)){
//print out the field values and values using print_r
echo '<pre>';
print_r($array);
echo '</pre>';
//using print_r is just to show every value, if you want to select
// --> a specific value, you can use this syntax:
// --> $array['field1']
}
?>
mysql_query returns either an MySQL result resource or -if there an error occured- false.
If mysql_fetch_array grumble about the return value it probably was false - the query failed. http://de2.php.net/mysql_error[quote]mysql_error -- Returns the text of the error message from previous MySQL operation[/quote]
=>
<?php
//build our query
$db = mysql_connect('localhost', 'homtek_dclamp', 'my_password') or die(mysql_error());
mysql_select_db('homtek_homtek', $db) or die(mysql_error());
$query = "SELECT * `news`";
$query = mysql_query($query, $db) or die(mysql_error());
//loop through each record
while($array = mysql_fetch_array($query)) {
//print out the field values and values using print_r
echo '<pre>';
print_r($array);
echo '</pre>';
//using print_r is just to show every value, if you want to select
// --> a specific value, you can use this syntax:
// --> $array['field1']
}
?>
No, it should only print a more useful error message. And it did
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'news`' at line 1