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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:57:59+00:00 2026-06-06T15:57:59+00:00

I am using a db query that takes in a state and city then

  • 0

I am using a db query that takes in a state and city then spits out 10 fields. Currently I can only see those fields by using print_r. I tried a suggestion on the php manual site a for loop to print the fields however I can’t get it to work properly. Here is the code:

    if (!$result) {
        echo 'Could not run query: ' . mysql_error();
        exit;
    }
    if (mysql_num_rows($result) > 0) {
        while ($row = mysql_fetch_assoc($result)) {
            print_r($row)."</p>";
            $arrayLength = count($row);
            for ($i = 0; $i < $arrayLength; $i++){
                echo "arrayName at[" . $i . "] is: [" .$row[$i] . "]<br>\n";
            }
                
                
        }

    }

And this is the result:

Array ( [id] => 1299 [zip_code] => 04011 [city] => Brunswick [county] => Cumberland [state_name] => Maine [state_prefix] => ME [area_code] => 207 [time_zone] => Eastern [lat] => 43.9056 [lon] => -69.9646 ) ....
arrayName at[0] is: []
arrayName at[1] is: []
arrayName at[2] is: []
arrayName at[3] is: []
arrayName at[4] is: []
arrayName at[5] is: []
arrayName at[6] is: []
arrayName at[7] is: []
arrayName at[8] is: []
arrayName at[9] is: []

Any ideas why I am not able to properly print the fields and their values? Also my code fails if the query returns more than one row as the current code doesn’t really accommodate it.

I put $i in the body of the for loop to see if it was working properly. Ideally I would have the field name where $i is and the value to the right of it after the colon.

  • 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-06T15:58:01+00:00Added an answer on June 6, 2026 at 3:58 pm

    you are fetching with mysql_fetch_assoc so
    change loop into

    foreach($row as $key => $value){
    echo "Array key : $key = $value <br/>";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query that I know can be done using a subselect, but
I need a SQLite query that searches 1 field only using LIKE. Basic example:
Context In our application, we snapshot data from a database using a query that
How to fill multiple tables in a dataset. I m using a query that
Using Microsoft SQL server 2008 I have a query that is in need of
I have a query that searches for clients using like with wildcard. For example:
I am using in C# MYsql .I have query that works if I run
I have this query that inserts rows, using a subquery like so: INSERT INTO
I am using mssql and I want to make a query that returns a
I've got a query that returns a proper result set, using SQL 2005. It

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.