I snarfed this from ScriptyGoddess because I thought it was a good idea to capture code snippets somewhere on this site too. This is her PHP/MySQL snippet. I have a hard time remembering this too.
$databaseName = "YOURDATABASENAME";
$dbconnection = mysql_connect("localhost", "DATABASE-USERNAME", "DATABASE-PASSWORD" or
die ('I can’t connect to the database.');
mysql_select_db($databaseName,$dbconnection);
$value = "SOMEVALUE";
$query = sprintf("SELECT FIELDNAME from TABLENAME where FIELDNAME='%s';", $value);
$result = mysql_query($query);
$totalNum = mysql_num_rows($result);
while ($row = mysql_fecth_array($result)) {
echo $row['FIELDNAME'];
}
////////OR//////
for ($i =0; $i < $totalNum; $i++) {
$row = mysql_fecth_array($result);
echo $row['FIELDNAME'];
}
Comments
Post new comment