dont show empty mysql field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
johntp
Forum Newbie
Posts: 3
Joined: Mon Jun 23, 2008 12:57 pm

dont show empty mysql field

Post by johntp »

Hey guys I got this script from http://www.phpguru.org/static/TableEditor.html and http://www.phpguru.org/downloads/TableEditor/TableEditor.phps I have it setup how I want it for the most part, but i cannot figure out how to hide the empty fields. I have a noDisplay function I would like to call to but I'm not sure how to do this.

my no Display function

Code: Select all

 
        function noDisplay()
        {
            $args = func_get_args();
 
            foreach ($args as $a) {
                if (isset($this->fields[$a])) {
                    $this->fields[$a]['noDisplay'] = true;
                }
            }
        }
 
how i view the table.

Code: Select all

 
        /**
        * Handles viewing a row
        */
        function handleView($id)
        {
            $quotedId = $this->dbQuote($id);
 
            foreach ($this->fields as $f => $v) {
                if (empty($v['noDisplay2'])) {
                    $fields[] = $f;
                }
            }
 
            /**
            * Data filters
            */
            if (!empty($this->dataFilters)) {
                $filters = implode(' AND ', $this->dataFilters);
            } else {
                $filters = 1;
            }
 
 
            $fields = implode(', ', $fields);
            list($tables, $joinClause) = $this->getQueryTables();
 
            $row = $this->dbGetRow("SELECT $fields FROM $tables WHERE $joinClause AND $filters AND {$this->pk} = $quotedId");
            if ($row === false) {
                $this->errors[] = 'Failed to find specified row';
                return;
            }
 
            $this->parseResults($row);
 

I talked to the guy who wrote the script and all he says is
If it's the same field all the time, there's something like "hiddenColumns". If not, then define a callback function using AddCallback(). This function ia called just before each row is displayed so you can do anything you want to the row. The row data is passed as an arg. Use this for example:

Code: Select all

 
function RowCallback(&$row)
{
// Manipulate the row here
}
 
but i dont have any clue how to manipulate the row to call noDisplay on fields that are blank.

I've been ripping my hair out over this so help is GREATLY Appreciated
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: dont show empty mysql field

Post by Burrito »

I'm not 100% clear on your issue. You want to display something when there is a NULL value or an empty value from a MySQL database?
johntp
Forum Newbie
Posts: 3
Joined: Mon Jun 23, 2008 12:57 pm

Re: dont show empty mysql field

Post by johntp »

Right. I want to tell it something like if($fields !== "" then call function noDisplay.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: dont show empty mysql field

Post by Burrito »

Code: Select all

 
while($row = mysql_fetch_assoc($result))
{
   if($row['column'] == "")
      dofunction();
}
 
johntp
Forum Newbie
Posts: 3
Joined: Mon Jun 23, 2008 12:57 pm

Re: dont show empty mysql field

Post by johntp »

so does my function noDisplay go where the dofunction is or does it go after the dofunction?
Post Reply