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

  • Home
  • SEARCH
  • 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 8387313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:10:35+00:00 2026-06-09T18:10:35+00:00

I am trying to make a function which converts a mysql query result in

  • 0

I am trying to make a function which converts a mysql query result in to an array

In the function below i’m assuming to have fields isbn, title and rank but this will not always be the case.

Is there a way to retrieve a fields name along with the value without actually knowing any of this information prior? so that this function can be used with any mysql query result.

function

function mysqlToArray($result){

   $arr = array();
   $numRows = mysql_num_rows($result);//count
   if($numRows>0){
      for($i=0; $i<$numRows; $i++){
         $arr[] = array(
            "isbn"      => mysql_result($result, $i, "isbn"),
            "title"     => mysql_result($result, $i, "title"),
            "rank"      => mysql_result($result, $i, "rank"),                   
         );
      }
   }        

   return $arr;
}

example in use

function getProfitableBooks(){
    $q = "SELECT isbn, title, rank FROM ".TBL_BOOKS;

    $result = mysql_query($q, $this->connection);
    if(!$result || (mysql_numrows($result) < 1)){  
        return null;
    }
    return $this->mysqlToArray($result);
}
  • 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-09T18:10:37+00:00Added an answer on June 9, 2026 at 6:10 pm

    There is a great PHP function for this mysql_fetch_array

    You can view examples mysql_fetch_array in the PHP manual.

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

Sidebar

Related Questions

I'm trying to make it so I can write a function which defines a
trying to make a page which will recursively call a function until a limit
I have been trying to make a function in Haskell to take a ByteString
So I am trying to make a Function which returns a list of data,
I'm trying to make function primes which is a list of prime numbers, but
I am trying to make a function which can print a polynomial of order
I'm currently trying to make a set of conversion functions which, through one call,
Im trying to make a function, that takes an input, determines its value, and
Im trying to make a function that will return an element of type point:
Im trying to make a function that retrieves a value from the db, but

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.