I have two tables, the first is a 'users' table which has a column called 'store' and I also have a table called 'stores' with columns 'store number' 'store location'.
The column 'store' in the users table is a 'store number'.
What I'm trying to do is create a HTML table that is something like
Sample data:
Store number: 34 Store location: London Users: 34
Store Number | Store Location | Number of Users at this store|
So it would be something like select * from stores and for each create new row.
and for the number of users be something like sum * from users where 'store' = 'store number' from stores table.
I hope this makes sense,
Jack.
UPDATE:
This is correct:
$result = mysql_query("SELECT * FROM stores", $con) or die(mysql_error());
echo "<table border='1'>";
echo "<tr> <th>Store Number</th> <th>Store Location</th> <th>Number of Users</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['storenumber'];
echo "</td><td>";
echo $row['location'];
echo "</td><td>";
echo 'Amount of users here';
echo "</td></tr>";
}
echo "</table>";
Tables:
CREATE TABLE IF NOT EXISTS `stores` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`storenumber` int(11) NOT NULL,
`location` varchar(40) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
CREATE TABLE IF NOT EXISTS users (
`id` int(50) NOT NULL AUTO_INCREMENT,
`email` varchar(50) NOT NULL,
`store` int(11) NOT NULL,
`lastvisit` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=28 ;