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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:46:12+00:00 2026-05-26T19:46:12+00:00

I need to grab the result of a query, with php from a mysql

  • 0

I need to grab the result of a query, with php from a mysql database. I have searched around and I think what I have should work, but it doesn’t. I’m running it in the correct folder. If there is anything else anyone can tell me, it would be greatly appreciated.

Thanks!

Here is my code.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
    <?php
        // define DB connection variables
        $host = "localhost";
        $user = "root";
        $password = "";
        // connect to the MySQL server
        $db_connection = mysql_connect($host,$user,$password);

        // If the connection failed:
        if(!$db_connection){
            echo "Error connecting to the MySQL server: " . mysql_error();
            exit;
        }
        mysql_select_db("hockey");

        // Execute an SQL SELECT query to pull back rows where Kessel scores
        $query = "SELECT COUNT(*) FROM goals WHERE player_id = 4";
        $response = mysql_query($query) or die(mysql_error());
    ?>

    <?php
        while($row= mysql_fetch_array($response));{

        echo $row['COUNT(*)'];

        // get the next row's details and loop to the top

        }
    ?>
</body>
</html>
  • 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-26T19:46:12+00:00Added an answer on May 26, 2026 at 7:46 pm

    You have an error here:

    while($row= mysql_fetch_array($response));{
    

    Infact you have the semicolon after the while and before the { (it should not be there).

    Anyway, since you’re retrieving just one field, the while is useless at all. Get rid of it and do something like this:

    $query = "SELECT COUNT(*) as Count FROM goals WHERE player_id = 4";
    $response = mysql_query($query) or die(mysql_error());
    $row= mysql_fetch_array($response);
    echo $row['Count'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to grab all the FIELD and VALUES from a POST. I have
I need to grab all records from a database table where the values in
My App needs to connect to and grab data from a MySQL database sitting
I need to grab all categories that don't have subcategories 1 ^--1.1 ^--1.2 ^--1.2.3
I need to findout a better and quick way to query MySQL table to
I have this query: public function checkUser($phone) { $sql = SELECT name FROM users
I have a table containing pagehit (normalized) data and I need to grab the
I have the need to move members from ExpressionEngine to WordPress. So far, I've
I need to join another table to my query, and grab the max value
I have been working on a script that pulls testimonials from a database, adds

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.