logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Coding & Scripting Corner View previous topic :: View next topic
Reply to topic   Topic: Getting values from $obj = mysqli_fetch_object($result)
Author
walt



Joined: 24 Oct 2015
Posts: 25

PostPosted: Fri 11 Dec '15 8:39    Post subject: Getting values from $obj = mysqli_fetch_object($result) Reply with quote

Hello again, I have the following code that is returning the correct value for '$table_name':
Code:
$obj = mysqli_fetch_object($result);
$table_name = $obj->items_table;

However, what I would like to do is this:
Code:
define('PRODUCT_ITEMS_TABLE_HEADER', 'items_table');
.
.
$obj = mysqli_fetch_object($result);
$table_name = $obj->PRODUCT_ITEMS_TABLE_HEADER;

This leaves no value in $table_name. Is there a way to use a definition after '$obj->' ?

Thanks!
Back to top
walt



Joined: 24 Oct 2015
Posts: 25

PostPosted: Fri 11 Dec '15 15:25    Post subject: Reply with quote

I was able to solve the problem using this code:
Code:

define('PRODUCT_ITEMS_TABLE_HEADER', 'items_table');
.
.
$row = $result->fetch_assoc();
$table_name = $row[PRODUCT_ITEMS_TABLE_HEADER];

Then realized that not being able to use $obj->SOME_DEFINITION, is probably not specific to mysqli, but a general PHP error, and tried this simpler example:
Code:
<?php

define('CLASS_PROPERTY', 'model');

class mini{

    private $model;
   
    public function __construct() {
        $this->model = "cooper";
        echo $this->CLASS_PROPERTY;
       
        $error = error_get_last();
        echo $error[message];
    }
}
$car = new mini();

?>

Output:
Code:
Undefined property: mini::$CLASS_PROPERTY

In this context, PHP will not resolve the definition?
Back to top
DR_LaRRY_PEpPeR



Joined: 26 Nov 2015
Posts: 7

PostPosted: Sat 12 Dec '15 2:38    Post subject: Reply with quote

Hi again. Smile

To use a dynamic property, you can just add braces:

$obj->{SOME_DEFINITION}
Back to top
walt



Joined: 24 Oct 2015
Posts: 25

PostPosted: Sat 12 Dec '15 5:48    Post subject: Reply with quote

Hello, and thank you again! I spent hours on it, when it didn't even matter anymore. Best I came up with was an ugly looking the exec() function.

I would like to say, that's it. Now I can finish my project without any more questions Wink.
Back to top


Reply to topic   Topic: Getting values from $obj = mysqli_fetch_object($result) View previous topic :: View next topic
Post new topic   Forum Index -> Coding & Scripting Corner