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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:05:46+00:00 2026-05-17T22:05:46+00:00

Firstly, sorry about the long question… but this is doing my head in. Any

  • 0

Firstly, sorry about the long question… but this is doing my head in. Any help would be greatfully accepted.

I’ve written the following function to return data from a mysql database:

function injuryTable()
{
    # get all players that are injured and their injuires...
    $sql = "SELECT players.id, players.injury_id, players.pname, injuries_date.name, start_date, end_date
            FROM players INNER JOIN injuries_date
            ON injury_id = injuries_date.id";

    $result = sqlQuery($sql);

    return $result;
}

The sqlQuery function is as follows:

function sqlQuery($sql)
{
    $products = array();
    $link = dbConnect('localhost', 'root', '', 'umarrr');
    $result = mysqli_query($link, $sql); 

    while ($row = mysqli_fetch_array($result))
    {
        $products[] = $row;        
    }

    #   return each row:
    return $products;
    #mysqli_close($link);
}

It’s all connected to the database, and everything works fine.
However when I try to iterate through the results: it only returns one row:

$injury_table = injuryTable();

// make it more readable:
foreach ($injury_table as $table);
{
    echo $table['pname'];
    echo $table['name'];
    echo $table['start_date'];
    echo $table['end_date'];
}

The sql statement I wrote above works perfectly in mysql query browser, so does anyone know what the problem here might be?

Output of print_r($injury_table)

Array ( [0] => Array ( [0] => 1 [id] => 1 [1] => 6 [injury_id] => 6 [2] => person [pname] => person [3] => wrist [name] => wrist [4] => 2008-11-21 [start_date] => 2008-11-21 [5] => 2010-11-11 [end_date] => 2010-11-11 ) [1] => Array ( [0] => 2 [id] => 2 [1] => 5 [injury_id] => 5 [2] => woman [pname] => woman [3] => neck [name] => neck [4] => 2009-11-12 [start_date] => 2009-11-12 [5] => 2010-09-09 [end_date] => 2010-09-09 ) [2] => Array ( [0] => 3 [id] => 3 [1] => 4 [injury_id] => 4 [2] => girl [pname] => girl [3] => groin [name] => groin [4] => 2010-11-27 [start_date] => 2010-11-27 [5] => 2010-12-01 [end_date] => 2010-12-01 ) [3] => Array ( [0] => 4 [id] => 4 [1] => 1 [injury_id] => 1 [2] => boy [pname] => boy [3] => achilles [name] => achilles [4] => 2010-02-01 [start_date] => 2010-02-01 [5] => 2010-03-23 [end_date] => 2010-03-23 ) [4] => Array ( [0] => 5 [id] => 5 [1] => 2 [injury_id] => 2 [2] => man [pname] => man [3] => toe [name] => toe [4] => 2010-01-01 [start_date] => 2010-01-01 [5] => 2010-02-02 [end_date] => 2010-02-02 ) )
  • 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-17T22:05:47+00:00Added an answer on May 17, 2026 at 10:05 pm

    Some things to check:

    1. Check the return value of mysqli_query(). You assume the query succeeds, and there’s far too many reasons for a query to fail to NOT check each time. It will return boolean FALSE on failure.
    2. If you’re doing many queries in your script, you’ll be opening a new connection handle for each. By default these will NOT be persistent connections, so any transactions you may start will be automatically rolled back after the query results are consumed. Generally it’s better to connect to the database ONCE (you can store the handle in a static variable inside your sqlQUery() function if you’d like and reuse it. There aren’t many situations where you’d want (or need) multiple handles at the same time, or a brand new sparkling clean handle each time.
    3. Have you tried doing a print_r()/var_dump() of the rows as they’re retrieved in the while() loop? Tried spitting out a mysqli_num_rows() to see how many the PHP version of the query is returning?
    4. Are you viewing the results in a browser? Perhaps something in the first or second result rows has an HTML tag (or something that your browser’s interpreting) as an HTML tag and is “hiding” the output. View the page’s source to make sure they’re really not being output, and not just being hidden.
    5. And finally, on the security front, it is very poor practice to allow a web-facing application to connect to the database as ‘root’. Any flaws in your code will leave the DB server wide open for anyone to play in. Create an account with the least amount of privileges necessary to get the job done (probably insert/update/select/delete only) and use that instead of the root account. Even if you’re just playing around with this on a private server, it’s a good habit to get into.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly sorry for the long piece of code pasted below. This is my first
Greetings, everyone: Firstly, sorry that my Flow description is long winded, but I think
Firstly, this is not a question about repository synchronisation for which there are numerous
Firstly, sorry for my English (I'm from China). By reading this article( how to
Firstly, I want to restrict this question to web development only. So this is
Firstly, I've never used threads, but have found lots of examples on the internet
I am sorry if the title is unclear. Allow me to elaborate further. Firstly,
I am going to ask you this question here since I cannot find answer
Firstly, is it possible? Been struggling with this one for hours; I think the
Firstly, this seems like (from ContourPlot) a fairly straightforward maximization problem, why is FindMaximum

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.