Hi..
I have a database that I am working with that has 8 different fields in it. one of those fields is called Mode
The Mode field contains entries like
A
B C
AB1
AA
D2
ect..
I need to create an output so it would list like
Total Mode A entries = xxx
Total Mode AB1 entries = xxxx
I need to come up with the total amount for each type in the mode field.
I am thinking I can do it with this SQL:
SELECT count(*), Mode
FROM ToolLogBook
GROUP BY Mode
But I'm not sure how to display it.
Any help would be appreciated....
TIA Rick
Help with SQL and how to display in php.
Moderator: General Moderators
-
jankidudel
- Forum Commoner
- Posts: 91
- Joined: Sat Oct 16, 2010 4:30 pm
- Location: Lithuania, Vilnius
Re: Help with SQL and how to display in php.
What do you mean not sure how to display ? Yo don't know how to print them on page or you think it will be not correct ?
Re: Help with SQL and how to display in php.
I'm not sure how to print them I am assuming that an array will be returned and that is the part I am not understanding. I'm still not sure if the SQL will work but I think from everything i read that this should do what I want it to...
Rick
Rick
Re: Help with SQL and how to display in php.
Is it MySQL?
Using PHP, you would use the mysql_query(), mysql_fetch_assoc() or mysql_fetch_array() or perhaps even mysql_result() to deal with the data and echo or print to display to the browser.
If you're not using mysql, there are similar functions available for the database of your choice.
MySQL function list:
http://www.php.net/manual/en/ref.mysql.php
Using PHP, you would use the mysql_query(), mysql_fetch_assoc() or mysql_fetch_array() or perhaps even mysql_result() to deal with the data and echo or print to display to the browser.
If you're not using mysql, there are similar functions available for the database of your choice.
MySQL function list:
http://www.php.net/manual/en/ref.mysql.php
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Re: Help with SQL and how to display in php.
I am using MySQL for the database.
Re: Help with SQL and how to display in php.
I am also not sure of the correct way to output this so it prints the Mode and the total number or returns for each mode. Sorry for seeming dumb but it's been quite a few years since I have done much PHP programming and this old brain has trouble remembering..
-
jankidudel
- Forum Commoner
- Posts: 91
- Joined: Sat Oct 16, 2010 4:30 pm
- Location: Lithuania, Vilnius
Re: Help with SQL and how to display in php.
<?php
mysql_connect('localhost', 'db', 'pass');
mysql_query('USE db);
$result = (mysql_query('SELECT mode, COUNT(*) FROM toollogbook GROUP BY mode'));
echo "<table border='1'>";
echo "<tr><th>Mode</th><th>Count</th></tr>";
while($row = mysql_fetch_row($result))
{
echo "<tr>";
echo "<td>$row[0]</td><td>$row[1]</td>";
echo "<tr>";
}
echo "</table>";
?>
mysql_connect('localhost', 'db', 'pass');
mysql_query('USE db);
$result = (mysql_query('SELECT mode, COUNT(*) FROM toollogbook GROUP BY mode'));
echo "<table border='1'>";
echo "<tr><th>Mode</th><th>Count</th></tr>";
while($row = mysql_fetch_row($result))
{
echo "<tr>";
echo "<td>$row[0]</td><td>$row[1]</td>";
echo "<tr>";
}
echo "</table>";
?>
Code: Select all