johntp Posted June 20, 2008 Share Posted June 20, 2008 Hey guys I have a nifty script, but when i display stuff from the DB it even shows empty fields. I want to only see fields with info in them. Any ideas? Quote Link to comment Share on other sites More sharing options...
DarkerAngel Posted June 20, 2008 Share Posted June 20, 2008 if(!$field == "") { ... } Quote Link to comment Share on other sites More sharing options...
johntp Posted June 20, 2008 Author Share Posted June 20, 2008 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; Quote Link to comment Share on other sites More sharing options...
DarkerAngel Posted June 20, 2008 Share Posted June 20, 2008 <?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. Quote Link to comment Share on other sites More sharing options...
johntp Posted June 20, 2008 Author Share Posted June 20, 2008 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 Quote Link to comment Share on other sites More sharing options...
DarkerAngel Posted June 20, 2008 Share Posted June 20, 2008 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; } } } ?> Quote Link to comment Share on other sites More sharing options...
johntp Posted June 20, 2008 Author Share Posted June 20, 2008 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 Quote Link to comment Share on other sites More sharing options...
johntp Posted June 20, 2008 Author Share Posted June 20, 2008 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); Quote Link to comment Share on other sites More sharing options...
DarkerAngel Posted June 20, 2008 Share Posted June 20, 2008 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 Quote Link to comment Share on other sites More sharing options...
johntp Posted June 20, 2008 Author Share Posted June 20, 2008 PHP Parse error: syntax error, unexpected ';', expecting ':' in C:\Hickham Website\EDB\TableEditor.php on line 1203 line 1203 was the: <?else?> Quote Link to comment Share on other sites More sharing options...
DarkerAngel Posted June 20, 2008 Share Posted June 20, 2008 I said I'm not sure how to use conditional statements in that method Quote Link to comment Share on other sites More sharing options...
widox Posted June 20, 2008 Share Posted June 20, 2008 <?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. Quote Link to comment Share on other sites More sharing options...
johntp Posted June 20, 2008 Author Share Posted June 20, 2008 Ok. Now im not getting any errors, I put <?else:?> but it still doesnt work. Quote Link to comment Share on other sites More sharing options...
widox Posted June 20, 2008 Share Posted June 20, 2008 Ok. Now im not getting any errors, I put <?else:?> but it still doesnt work. What does that mean? Are you getting any errors? Quote Link to comment Share on other sites More sharing options...
johntp Posted June 20, 2008 Author Share Posted June 20, 2008 I'm not getting any errors such as PHP Parse error: syntax error, unexpected ';', expecting ':' in C:\Hickham Website\EDB\TableEditor.php on line 1203 But that code didn't hide the empty fields. Quote Link to comment Share on other sites More sharing options...
widox Posted June 20, 2008 Share Posted June 20, 2008 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 Quote Link to comment Share on other sites More sharing options...
johntp Posted June 20, 2008 Author Share Posted June 20, 2008 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. Quote Link to comment Share on other sites More sharing options...
johntp Posted June 24, 2008 Author Share Posted June 24, 2008 bump Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 24, 2008 Share Posted June 24, 2008 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.