Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8707971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:59:55+00:00 2026-06-13T03:59:55+00:00

I have a table rel ——————— |id|refid|cellid|cat| |1 |1 |1 |1 | |2 |2

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:59:57+00:00Added an answer on June 13, 2026 at 3:59 am

    You are adding the rows to a new array called “$array” not “$cell_array” so $cell_array is empty.

    give count(*) an alias as mentioned by John and then

    change

    $array[] = $row;
    

    to

    $cell_array[$row["cellid"]] = $row['totalcount'];
    

    to pull a value out use:

    echo $cell_array[x];
    

    where x is the cellid you want a count for.

    also I assume you wanted to use a Constant for the “DATABASE” so change

    if ( !@mysql_select_db("DATABASE") ) {
    

    to

    if ( !@mysql_select_db(DATABASE) ) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table rel with fields id refid cellid cat and some working
I have table with around 70 000 rows. There is 6000 rows that i
I have table in which I am inserting rows for employee but next time
In oracle: I have a table rel with these columns (object_id1, object_id2) that relates
I have a MANY_MANY relation: 'rel'=>array(self::MANY_MANY, 'MyClass','table(id_1,id_2)', 'condition'=>'some condiotions AND field_name=:param') I get the
I have many table cells which I want to show a tooltip once hovered.
I have this table that is currently 1200+ rows, of which these rows have
I have table, and I want check/uncheckcheck box not only by clicking on checkbox,
I want to have a table that the user can expand/contract the contents (but
I have a table Item with a number of related items, like so: ID

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.