Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read and List MySQL table columns even if table is blank

Status
Not open for further replies.

southbeach

Programmer
Jan 22, 2008
879
US
Howdy!

I have decided to write a couple of classes where I can reference tables dynamically and have variables set dynamically based on name of columns (not sure how good of an idea this is - lol).

I recently started using Linux NetBean IDE and it suggests that I keep my methods to no more than 20 lines - never heard this but I'll take it at face value and so, I'm trying to shrink my code as much as possible (and a bit of change of style + laziness).

So, with this approach, I should be able to set any number of
Code:
$this->$query[$key]='some value'

NOTE: where $query[$key] represents the column's name as queried or read!

Here is a snippet of what I have when loading a row
Code:
        if ($query) {
            $job = mysqli_fetch_assoc($query);
            foreach ($job as $key=>$value) {
                $this->$key=$value;
            }
        } else { $this->job(); }

I want to do same in job() to set all possible $this->[name] to blank ...

Thank you all in advance for your assistance!

PS: I feel that I am asking is very simple question in a very complicated way!

--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
The answer for future reference:
Code:
        $sql='DESCRIBE `orderh`;';
... ... ...
        while($row = mysqli_fetch_array($query)) { 
            $this->{$row['Field']}='';
        }

and this is how I successfully set variables to batch columns' names without having to type them in manually.



--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top