Hello im trying to get this count function working when i had it in php its jus printin the statement and aint showing any results but works in mysql admin why is this??
$query="SELECT COUNT(*) FROM oeter WHERE monday='n' ";
echo $query;
count function in php/mysql
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: count function in php/mysql
You need to pass the query through mysql_query(), then fetch the results using mysql_fetch_assoc()..
the manual has plenty of examples
the manual has plenty of examples
Re: count function in php/mysql
i got 2querys running at the same time thats y i think
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: count function in php/mysql
Please don't use AOL speak since we have many people with english as a second language, and may not understand abbreviations.
As to your problem, I don't understand what you mean.
Post all relevant code.
As to your problem, I don't understand what you mean.
Post all relevant code.
Re: count function in php/mysql
Sorry about that his my code
Code: Select all
<!-----Display data in textboxes PHP----->
<?
// Standard SQL
$query ="SELECT COUNT(*) FROM peter WHERE day='no'";
$query = "SELECT Code FROM Records WHERE lock= '".$_SESSION['name']."'";
// Connect to DB server
$connection = mysql_connect("", "", "");
if (!$connection)
die("Cannot connect to DB");
// Select database
mysql_select_db("", $connection)
or die("Cannot find DB");
$result = mysql_query($query, $connection);
// Loop through data and display
while($row = mysql_fetch_array($result))
{
code = $row['Code'];
}
// Close connection ! (please !)
mysql_close($connection);
?>- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: count function in php/mysql
So what is the problem? I see you have 2 different $sql variables, however the first one is overwritten by the second.
You need to run the first SQL before rewritting it to a different query.. or use different variable names
You need to run the first SQL before rewritting it to a different query.. or use different variable names
Code: Select all
$sql1 = 'SELECT COUNT(*) ...';
$result1 = mysql_query($sql1) or die(mysql_error());
$sql2 = 'SELECT * ....';
$result1 = mysql_query($sql2) or die(mysql_error());