Jump to content

Hide empty fields in an MySQL Table.


johntp

Recommended Posts

I forgot to mention, I have a function that is called noDisplay, which will hide the table

 

        function noDisplay()

        {

            $args = func_get_args();

 

            foreach ($args as $a) {

                if (isset($this->fields[$a])) {

                    $this->fields[$a]['noDisplay'] = true;

                }

            }

        }

 

so could i do something like

 

if(!$field == "")
['noDisplay'] = true;

 

 

Link to comment
Share on other sites

<?php
        function noDisplay()
        {
            $args = func_get_args();

            foreach ($args as $a) {
                if (!isset($this->fields[$a]) || $field != "") { //For one you had this statement true if the field HAS a value
                    $this->fields[$a]['noDisplay'] = true;
                }
            }
        }
?>

I don't do much OOP but that should work. If your "noDisplay" works properly.

Link to comment
Share on other sites

I'm getting this at the bottom of the page, and it's not hiding what i need it to. Here is a look at the code being used for this. http://www.phpguru.org/static/TableEditor.html and http://www.phpguru.org/downloads/TableEditor/TableEditor.phps

 

PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: field in C:\Hickham Website\EDB\TableEditor.php on line 438
Link to comment
Share on other sites

My fault didn't conform my code to yours.

<?php
        function noDisplay()
        {
            $args = func_get_args();

            foreach ($args as $a) {
                if (!isset($this->fields[$a]) || $fields[$a] != "") { //For one you had this statement true if the field HAS a value
                    $this->fields[$a]['noDisplay'] = true;
                }
            }
        }
?>

Link to comment
Share on other sites

still didn't work :(

 

PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438 PHP Notice: Undefined variable: fields in C:\Hickham Website\EDB\TableEditor.php on line 438
Link to comment
Share on other sites

These are the codes im using

 

For the function

        function noDisplay2()
        {
            $args = func_get_args();

            foreach ($args as $a) {
                if (!isset($this->fields[$a]) || $fields[$a] != "") { //For one you had this statement true if the field HAS a value
                    $this->fields[$a]['noDisplay2'] = true;
                }
            }
        }

 

 

To show the table

        /**
        * 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);

Link to comment
Share on other sites

Okay I just took a look at the code your using in whole. That function works in a different way so my method wouldn't work.

 

so your trying to hide an empty field

                <?foreach($row as $field => $v):?>
                    <?if(empty($this->fields[$field]['noDisplay'])):?>
                        <td valign="top"><?=$v // Do not do htmlspecialchars here - it's now implemented as a display filter?></td>
                    <?endif?>
                <?endforeach?>

::to::

                <?foreach($row as $field => $v):?>
                    <?if(empty($this->fields[$field]['noDisplay']) || $v != ""):?>
                        <td valign="top"><?=$v // Do not do htmlspecialchars here - it's now implemented as a display filter?></td>
                    <?else?>
                        <td valign="top">&npsp;</td>
                    <?endif?>
                <?endforeach?>

I'm really not keen to this type of code so I may not have it done correctly

Link to comment
Share on other sites

               <?foreach($row as $field => $v):?>
                    <? if(empty($this->fields[$field]['noDisplay']) || $v != ""): ?>
                        <td valign="top"><?=$v // Do not do htmlspecialchars here - it's now implemented as a display filter?></td>
                    <? else: ?>
                        <td valign="top">&npsp;</td>
                    <? endif; ?>
                <?endforeach; ?>

 

Try that, you were missing a colon after the else and semi-colon after endif and endforeach.

Link to comment
Share on other sites

If you do a print_r($row); directly above the foreach loop your certain that there are empty field values there? Could the value of $v be a space ' '?

Not sure what the calling code looks like so I can't tell you anything specific. Best way is to step through it with print_r()'s and echo()'s to make sure your values are what you think they are.

 

HTH

Link to comment
Share on other sites

I was told by the guy who made this script:

 

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:

 

$editor->AddCallback('RowCallback'); //this goes on the index.php page

function RowCallback(&$row) //this goes on the tableeditor.php page
{
// Manipulate the row here
}

 

the only problem is I don't know how to manipulate the row to only show fields with data in it.

Link to comment
Share on other sites

To widox ... why are you going in and out of PHP on each statement and why are using short tags?

This way of writing PHP is rediculous:

     <?foreach($row as $field => $v):?>
             <? if(empty($this->fields[$field]['noDisplay']) || $v != ""): ?>
                      <td valign="top"><?=$v // Do not do htmlspecialchars here - it's now implemented as a display filter?></td>
              <? else: ?>
                       <td valign="top">&npsp;</td>
               <? endif; ?>
       <?endforeach; ?>

It can written much in a much more easily understood format:

<?php
   foreach($row as $field => $v) {
        if(empty($this->fields[$field]['noDisplay']) || $v != "")
             echo '<td valign="top">' . $v . '></td>';
        else
             echo '<td valign="top">&npsp;</td>';
   }
?>

 

Ken

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.