Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
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.
| |
|
Topic: Getting values from $obj = mysqli_fetch_object($result) |
|
Author |
|
walt
Joined: 24 Oct 2015 Posts: 25
|
Posted: Fri 11 Dec '15 8:39 Post subject: Getting values from $obj = mysqli_fetch_object($result) |
|
|
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
|
Posted: Fri 11 Dec '15 15:25 Post subject: |
|
|
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
|
Posted: Sat 12 Dec '15 2:38 Post subject: |
|
|
Hi again.
To use a dynamic property, you can just add braces:
$obj->{SOME_DEFINITION} |
|
Back to top |
|
walt
Joined: 24 Oct 2015 Posts: 25
|
Posted: Sat 12 Dec '15 5:48 Post subject: |
|
|
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 . |
|
Back to top |
|
|
|
|
|
|