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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:54:58+00:00 2026-06-13T12:54:58+00:00

student table contains: id firstname lastname function get_db_fields get student table fields. class Student{

  • 0

student table contains:
id
firstname
lastname

function get_db_fields get student table fields.

class Student{

public function get_db_fields(){
        $sql = "SELECT * FROM students";
        $result = mysql_query($sql);
        if(!$result){
         die("Failed :" . mysql_error());
        }
        $db_fields = array();
        while($field = mysql_fetch_field($result)){
           $db_fields[] = "'".$field->name."'";
        }
        return join(',',$db_fields);
    }

    public $db_fields = array($this->get_db_fields()); <--- This is not working

}

return join(‘,’,$db_fields) = ‘id’,’firstname’,’lastname’

my question is how I am going set the return value into public $db_fields.
So public $db_fields will be “public $db_fields = array(‘id’,’firstname’,’lastname’)”

What i’ve tried so far

1.)

public $db_fields = array($this->get_db_fields()); <--- This is not working

Error: Parse error: syntax error, unexpected T_VARIABLE in C:\Program Files\xampp\htdocs\ieti\includes\student.php on line 33

2.) $database_fields = $this->get_db_fields();

Error: Parse error: syntax error, unexpected T_VARIABLE in C:\Program Files\xampp\htdocs\ieti\includes\student.php on line 33

  • 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-13T12:54:59+00:00Added an answer on June 13, 2026 at 12:54 pm

    Create a constructor and assign the returned value from get_db_fields to the member variable db_fields. Member variables can only be initialized with values that are evaluated at compilation.

    class Student{
    
      public $db_fields;
    
      public function __construct() {
        $this->db_fields = $this->get_db_fields();
      }
    
    // Rest of your code
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a table Students which contains the following colums: Id,FirstName,LastName,Adress . The colum
I have a STUDENT table which contains data about students from a faculty: STUDENT(ID,
I created one app for database which contains a student table and 3 fields
Suppose I have a student table contains id , class , school_id having 1000
I have a database with 3 tables. The first table contains students with fields
I have bind 2 separate tables using BindingSource. Left grid contains student table and
I have a table which contains student grades (SAG). I need to show all
I have a table contains bus and student sign up information: CREATE TABLE [dbo].[BusSignupInstance](
I am having two tables student table it contains (Student_id,school_code,name,year,...) school table it contains
In MySQL, I have a Student Table which contains a StudnetId column which goes

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.