Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Streda, 25. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  I'm sure this could be done better...

phpMyEdit General     I'm sure this could be done better...
Odoslať novú tému   Odpovedať na tému    
 
foxylady337     Založený: 24.07.2008   Príspevky: 10  
Príspevok Zaslal: 2008-07-24 18:13
Návrat hore  Odpovedať s citátom     

I manage the website of my local Rotary Club, with a database of members, committees, office-bearers etc.

Each committee has a chairman and up to 9 members, and tbl_committees has columns for these members, referring back to tbl_members using a unique key ('counter') to pick up the member's 'name' and 'initial' for display.

Here is the section of code for editing the member9 column:

Kód:
$opts['fdd']['member9']['values']['table'] = 'tbl_members';
$opts['fdd']['member9']['values']['column'] = 'counter';
$opts['fdd']['member9']['values']['description']['columns'][0] = 'name';
$opts['fdd']['member9']['values']['description']['divs'][0] = ', ';
$opts['fdd']['member9']['values']['description']['columns'][1] = 'initial';
if ($opts['fdd']['member9']['values']['description'] = ', ') {
    $opts['fdd']['member9']['values']['description'] = '';
}
$opts['fdd']['member9']['values2'] = array("");
$opts['fdd']['member9']['sqlw'] = 'if($val = "", NULL, $val)';


Before I upgraded to version 5.7.1, I didn't need the "if" statement, when there was no member9 (i.e. the field was NULL) the entry in the column in the editing window was blank, but since the upgrade, ", " would appear.

I feel there must be some way of picking up the fact that a field is NULL before assembling the member's name.

TIA

 
michal     Založený: 17.06.2003   Príspevky: 537   Bydlisko: Slovakia
Príspevok Zaslal: 2008-08-01 10:15
Návrat hore  Odpovedať s citátom     

in the if you have = and not ==, so the if has no effect (it is always true)

 
foxylady337     Založený: 24.07.2008   Príspevky: 10  
Príspevok Zaslal: 2008-08-01 12:48
Návrat hore  Odpovedať s citátom     

Thank you.

I agree that "==" should be used as a comparison operator here, but in practice the fix-up code I've introduced (the "if" statement) does work as I'd intended! I get an individual's name in the member9 column if there is a ninth member of the committee, and a blank (not ", ") if the member9 field in the database is NULL.

I'd prefer to detect the NULL in the member9 column BEFORE trying to construct the individual's name, but may have to tolerate the fix.

 
michal     Založený: 17.06.2003   Príspevky: 537   Bydlisko: Slovakia
Príspevok Zaslal: 2008-08-01 12:55
Návrat hore  Odpovedať s citátom     

$opts['fdd']['member9']['values2'] = array("");

values2 excepts a key=>value syntax (there you have array(0=>"") implicitly)

try
array("" =>"")
or array(", "=>"")

which should overwrite description

 
foxylady337     Založený: 24.07.2008   Príspevky: 10  
Príspevok Zaslal: 2008-08-01 13:55
Návrat hore  Odpovedať s citátom     

Perfect! Thank you.

I must confess, I don't understand how to use values2, and had put in the line:

Kód:

$opts['fdd']['member9']['values2'] = array("");


because I'd seen it in a fragment of code elsewhere!

Is there a good description of how to use values and values2 somewhere - the manual says very little about values2 in particular.

 
michal     Založený: 17.06.2003   Príspevky: 537   Bydlisko: Slovakia
Príspevok Zaslal: 2008-08-01 15:18
Návrat hore  Odpovedať s citátom     

i guess http://opensource.platon.sk/projects/doc.php/phpMyEdit/html/configuration.input-restrictions.html

is the only place.

which code did work ?

 
foxylady337     Založený: 24.07.2008   Príspevky: 10  
Príspevok Zaslal: 2008-08-01 16:14
Návrat hore  Odpovedať s citátom     

Only the second one

Kód:
$opts['fdd']['member9']['values2'] = array(", " => "");


I still don't understand how it works, as it seems to interact with the ['values'] statements above in that these pick up the name of the committee member if there is one, or ", " if there isn't, and ['values2'] then converts ", " to "".

Very strange! And not mentioned in the manual...

 
michal     Založený: 17.06.2003   Príspevky: 537   Bydlisko: Slovakia
Príspevok Zaslal: 2008-08-01 16:29
Návrat hore  Odpovedať s citátom     

it should be mentioned that values and values2 can be combined.

values2 can override anything done by values. so your unwanted code ', ' is translated to ''.

 
foxylady337     Založený: 24.07.2008   Príspevky: 10  
Príspevok Zaslal: 2009-06-09 08:47
Návrat hore  Odpovedať s citátom     

I've been using the code discussed above for nearly a year, and recently entered the details of the club's committees for the year starting on 1st July 2009.

I have made no changes to the software since then, but when I went to the website to correct a mistake yesterday I was unable to do so because of an error message:

Citácia:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' = "", NULL, , ),`member8`=if(, = "", NULL, , ),`member9`=if(, = "", NULL, , ' at line 1


This happens for a committee which has no member7, member8 or member9, and it seems that $val is returning the unwanted ", " string, which started this topic.

Kód:
$opts['fdd']['member9']['values']['table'] = $TABLE_MEMBERS;
$opts['fdd']['member9']['values']['column'] = 'counter';
$opts['fdd']['member9']['values']['description']['columns'][0] = 'name';
$opts['fdd']['member9']['values']['description']['divs'][0] = ', ';
$opts['fdd']['member9']['values']['description']['columns'][1] = 'initial';
$opts['fdd']['member9']['values2'] = array(", " => "");
$opts['fdd']['member9']['sqlw'] = 'if($val = "", NULL, $val)';


This error message appears on my development machine as well as the live site, which means it's not a change to MySQL or php on the live site which has caused the problem.

The only explanation of the change is that my browser may have changed the behaviour of the code, perhaps because of an automatic upgrade in the browser or my antivirus software (AVG).

Can anyone explain this? And offer a solution?

TIA

 
doug     Založený: 10.02.2003   Príspevky: 1013   Bydlisko: Denver, Colorado (USA)
Príspevok Zaslal: 2009-06-09 20:41
Návrat hore  Odpovedať s citátom     

I don't think you can user both 'values' and 'values2', so try commenting out:

Kód:
$opts['fdd']['member9']['values2'] = array(", " => "");


 
foxylady337     Založený: 24.07.2008   Príspevky: 10  
Príspevok Zaslal: 2009-06-09 23:31
Návrat hore  Odpovedať s citátom     

I have solved my problem with this code:

Kód:
$opts['fdd']['member9'] = array(
  'name'     => 'Member9',
  'select'   => 'T',
  'maxlen'   => 4,
  'sort'     => true,
  'values'   => array(
      'table' => $TABLE_MEMBERS,
      'column' => 'counter',
      'description' => array(
          'columns' => array(
              '0' => 'name',
              '1' => 'initial'),
           'divs' => array(
              '0' => ', '),
          ),
    ),   
  'values2'  => array(", " => ""),
  'sqlw'     => 'if($val_qas = ", ", NULL, $val_qas)'
);


What I am doing here is editing details of several committees, each of which may have a chairman and up to nine members.

Column 'member9' is frequently empty, in which case its value should be NULL, but if there is a ninth member his surname and initials will be looked up in $TABLE_MEMBERS and presented in the form "Surname, Initials". Unfortunately, if there is no 9th member of the committee, ", " will appear where the name would have been, and this is what I've adjusted using values2.

Although the unwanted comma is suppressed in the table of committees, it will be returned at the end of the editing process, hence the final line, which recognises ", " as meaning there is no ninth member, and converts this to NULL.

I can't explain why the previous code worked OK in May and doesn't work in June, but the process of explaining it to the forum has enabled me to sort my own ideas out, and find an answer.

Many thanks for just being there to bounce ideas off.

 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov