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 786433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:02:25+00:00 2026-05-14T21:02:25+00:00

This might be easy for you guys but i could’t get it. I have

  • 0

This might be easy for you guys but i could’t get it.

I have a php class that query the database and return the query result. I assign the result to an array and wants to use it on my main.php script. I have tried to use echo $var[0] or
echo $var[1] but the output are ‘array’ instead of my value. Anyone can help me about this issue? Thanks a lot!

My php class

<?php 
class teamQuery {

            function teamQuery(){


            }
            function getAllTeam(){
                $connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
                    if (!$connection) {
                        die("Database connection failed: " . mysql_error());
                    }

                    $db_select = mysql_select_db(DB_NAME,$connection);
                    if (!$db_select) {
                        die("Database selection failed: " . mysql_error());
                    }

                  $teamQuery=mysql_query("SELECT * FROM team", $connection);

                    if (!$teamQuery){
                        die("database has errors: ".mysql_error());
                          }
                    $ret = array();   

                    while($row=mysql_fetch_array($teamQuery)){

                    $ret[]=$row;
                    }     
                    mysql_free_result($teamQuery); 

                    return $ret;
                    }


            }


?>

My php on the main.php

$getTeam=new teamQuery();
$team=$getTeam->getAllTeam();

   //echo $team[0] or team[1] output 'array' string!
  // while($team){
  // do something }  can't work either

  // How to loop through the values??

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-05-14T21:02:26+00:00Added an answer on May 14, 2026 at 9:02 pm

    You get this output because $team[0] and $team[1] are indeed arrays. They are the rows of your database table and every row consists of several fields, e.g. id, name etc.
    You have 2 dimensional array, that might look like this:

    Array
    (
        [0] => Array
            (
                [id] => 1
                [name] => foo
            )
    
        [1] => Array
            (
                [id] => 2
                [name] => bar
            )
    )
    

    To loop through the data, use for or foreach:

    foreach($team as $member) {
        foreach($member as $k=>$v) {
            echo $k . ': ' . $v;
        }
    }
    

    Also the documentation about arrays might be worth reading for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this might be an easy question but i have a notification that when clicked
I'm a newbie with PHP so this might be ridiculously easy question, but despite
this might have been answered or might be too easy, but I haven't found
Hie guys i am still learning cakephp so this question might be easy but
I know, that this might be super easy, but probably, working late just halted
This might be easy but i get a problem, How to test if the
this might be easy but I don´t see the way. I have a shopping
This might be an easy one for you guys, but I'm not sure the
This might be an easy thing to do that I missed, but I cannot
This might be ridiculously easy for you but I've been struggling with this for

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.