English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories



CDs in my collection :: Results



Search results




$db = mysql_connect("removed");
mysql_select_db("cdcol", $db);
$query = "SELECT cds.interpret, cds.jahr, cds.id, cds.titel FROM cds WHERE name LIKE '%".$_POST[name]."%'";
$result = mysql_query($query);
while ($record = @mysql_fetch_assoc($result)){
while (list($fieldname, $fieldvalue) = each ($record)){
echo $fieldname.": ".$fieldvalue."
";
}
echo "
";
}
?>


click here to go back to the search page


2006-08-31 06:50:27 · 1 answers · asked by Dan 1 in Computers & Internet Programming & Design



CDs in my collection :: Search



Search for a disk




Please enter the name, or part of the name of the CD you are seeking:












2006-08-31 07:01:39 · update #1

1 answers

First off, take out the @ before mysql_fetch_assoc. There may be an issue with the select that is causing this to break and so result won't be set.

If that is the case, fix the SQL.

I would also recommend using foreach instead of your second while -
foreach ( $record as $fieldname => $fieldvalue){
//do stuff
}
that will make it easier to read.

In general, don't suppress error messages using the @. The only time (and I discourage doing even this) it has a reason to be used is if a variable might or might not be set and it doesn't matter if it is or not. (for example a page that can process a form may or may not have all the variables set)

2006-08-31 10:12:17 · answer #1 · answered by John J 6 · 0 0

fedest.com, questions and answers