I have a table "rel"
---------------------
|id|refid|cellid|cat|
|1 |1 |1 |1 |
|2 |2 |1 |3 |
|3 |3 |1 |5 |
|4 |3 |5 |2 |
|5 |4 |2 |7 |
I want to count the number of rows with the same cellid for each cellid. Then have those counts retrievable in a HTML page.
I've written code to run the SQL query and store the results in an array
<?php
// Connect to the database server
$dbcnx = mysql_connect("localhost",USER,PASSWORD);
if (!$dbcnx) {
echo( "<P>Database Connection Failed</P>" );
exit();
}
// Select the matrix databse database
if ( !@mysql_select_db("DATABASE") ) {
echo( "<P>Not connected to Database</P>" );
exit();
}
$cell_array = array();
if ($result = mysql_query("SELECT cellid, COUNT(*) FROM rel GROUP BY cellid")) {
if (mysql_num_rows($result)) {
while ($row = mysql_fetch_assoc($result)) {
$array[] = $row;
}
}
}
?>
I then want to access this php script from another page using require, and then recover the count result for any cellid so that I can put the results in a HTML Table.
Is this the right way to approach this problem and if so what is the syntax of recalling values from this array, I have seen
echo $cell_array['cellid'];
used on other answers but it does not seem to work for me.
Thanks