View Single Post
  #1 (permalink)  
Old 2007-01-05, 09:30 PM
Wilson Wilson is offline
Junior Member
 
Join Date: Jan 2007
Posts: 12
Wilson is on a distinguished road
Default Help with Mysql syntax

Sorry if this is terribly basic.

Writing code such as this is easy
Code:
$sql2 = 'SELECT COUNT( DISTINCT `Author` ) FROM `books` LIMIT 0, 100';
but the $64 question is, whats next to make the result show up on a web page? I have this code, please refer to the above code at the bottom of the page

Code:
<?
$dbh=mysql_connect ("localhost", "XXXX", "XXXXX") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("lunar_effort", $dbh);
$sql = ("INSERT INTO `books`(`Book`, `Year`, `Author`, `Genre`, `Number`, `Series`, `Complete`,`Recommendation`, `Status`, `Key`)
VALUES ('$_POST[Book]', '$_POST[Year]', '$_POST[Author]', '$_POST[Genre]', '$_POST[Number]', '$_POST[Series]', '$_POST[Complete]', '$_POST[Recommendation]', '$_POST[Status]', NULL)");
if (!mysql_query($sql,$dbh))
  {
  die('Error: ' . mysql_error());
}
echo $_POST ["Book"],"<br />";
echo $_POST ["Year"],"<br />";
echo $_POST ["Author"],"<br />";
echo $_POST ["Genre"],"<br />";
echo $_POST ["Number"],"<br />";
echo $_POST ["Series"],"<br />";
echo $_POST ["Complete"],"<br />";
echo $_POST ["Recommendation"],"<br />";
echo $_POST ["Status"],"<br />";
echo "1 record added","<br />";
echo "The number of records is ";
$sql1 = "SELECT * FROM books";
$result = mysql_query($sql1,$dbh);
echo mysql_num_rows($result);
 echo "<br />";
echo "The number of Authors is ";
$sql2 = 'SELECT COUNT( DISTINCT `Author` ) FROM `books` LIMIT 0, 100';
$result = mysql_query($sql2,$dbh);
echo mysql_num_fields($result);
 mysql_close($dbh);
?>
Everything works perfectly till I get to this code
Code:
echo "The number of Authors is ";
$sql2 = 'SELECT COUNT( DISTINCT `Author` ) FROM `books` LIMIT 0, 100';
$result = mysql_query($sql2,$dbh);
echo mysql_num_fields($result);
At the $result part, I have no clue what I am doing to make it appear when called. Can anyone point at a tutorial that isnt just about how to write the Select Count part and how to echo the results?
(or help with the code as to what should be there?)

Last edited by Wilson; 2007-01-05 at 09:37 PM.
Reply With Quote
Sponsored Links