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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:03:15+00:00 2026-05-26T15:03:15+00:00

I want to have a SelectAll function which takes in a few arguments (class,

  • 0

I want to have a SelectAll function which takes in a few arguments (class, table, sort field, and sort order.) The comments explain what is going on (or what is supposed to.)

  public static function SelectAll($class, $table, $sort_field, $sort_order = "ASC")
  {

    /* First, the function performs a MySQL query using the provided arguments. */

    $query = "SELECT * FROM " .$table. " ORDER BY " .$sort_field. " " .$sort_order;
    $result = mysql_query($query);

    /* Next, the function dynamically gathers the appropriate number and names of properties. */

    $num_fields = mysql_num_fields($result);
    for($i=0; $i < ($num_fields); $i++)
    {
      $fetch = mysql_fetch_field($result, $i);
      $properties[$i] = "'".$fetch->name."'";
    }
    /*echo [$properties[0]; echo "<br />";}*/
    /* Finally, the function produces and returns an array of constructed objects. */

    while($row = mysql_fetch_assoc($result))
    { 
      for($i=0; $i < ($num_fields); $i++)
      {
        $args[$i] = $row[$properties[$i]];
      }
      $array[] = call_user_func_array(new $class, $args);
    } return $array; }

Now, the problem I am having is that $row[$properties[$i]] results in ‘undefined index.’

Right after the function gathers the number/names of the fields and stores them in an array, I can echo the value of $properties[0] and it shows as it should, ‘id’, but $row[~anything here~] will simply not work unless I manually enter the value, such as $row['id']. As you can imagine very frustrating and confusing.

Why won’t this work? Are there any solutions, or alternate ways of accomplishing this function?

  • 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-26T15:03:15+00:00Added an answer on May 26, 2026 at 3:03 pm

    As I see your $properties[$i] array items have quoted values like "'id'",
    so $row[$properties[$i]] <==> $row["'id'"] != $row["id"];

    And you might want to check $result === false after $result = mysql_query($query);

    Anyway, I think you could replace your function to this (unless you constructed it for demonstration only):

    public static function SelectAll($class, $method_name, $table, $sort_field, $sort_order = "ASC"){
      /* First, the function performs a MySQL query using the provided arguments. */
      $query = "SELECT * FROM " .$table. " ORDER BY " .$sort_field. " " .$sort_order;
      $result = mysql_query($query);
    
      while($row = mysql_fetch_array($result))
        $array[] = call_user_func_array(array($class,'__construct'), $row);
    
      return $array;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a class which implements an interface, which specifies the specific
I have two table emptable1(empid,status) emptable2(empid,week) i want to select all the empid whose
i have a GridView (selectable) in which I want to generate a dynamic GridView
want to have a Hyperlink-Button in a gridView in which I can display a
Strange question, I know. Allow me to explain. I have a JavaScript/jQuery function that
I have a web page on which there are several buttons and i want
I have some elements which i can select with .click() function and they became
I have got a HTML table which contain a check box in <TH> and
Let's say I have a data.table and I want to select all the rows
I have a Course class which contains collection of CourseItems . Each CourseItem has

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.