foxylady337
Joined: 24 Jul 2008
Posts: 10
Posted: 2008-07-24 18:13
Back to top
Reply with quote
|
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:
| Code: |
$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
Joined: 17 Jun 2003
Posts: 537
Location: Slovakia
Posted: 2008-08-01 10:15
Back to top
Reply with quote
|
in the if you have = and not ==, so the if has no effect (it is always true)
|
foxylady337
Joined: 24 Jul 2008
Posts: 10
Posted: 2008-08-01 12:48
Back to top
Reply with quote
|
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
Joined: 17 Jun 2003
Posts: 537
Location: Slovakia
Posted: 2008-08-01 12:55
Back to top
Reply with quote
|
$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
Joined: 24 Jul 2008
Posts: 10
Posted: 2008-08-01 13:55
Back to top
Reply with quote
|
Perfect! Thank you.
I must confess, I don't understand how to use values2, and had put in the line:
| Code: |
$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
Joined: 17 Jun 2003
Posts: 537
Location: Slovakia
Posted: 2008-08-01 15:18
Back to top
Reply with quote
|
i guess http://opensource.platon.sk/projects/doc.php/phpMyEdit/html/configuration.input-restrictions.html
is the only place.
which code did work ?
|
foxylady337
Joined: 24 Jul 2008
Posts: 10
Posted: 2008-08-01 16:14
Back to top
Reply with quote
|
Only the second one
| Code: |
| $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
Joined: 17 Jun 2003
Posts: 537
Location: Slovakia
Posted: 2008-08-01 16:29
Back to top
Reply with quote
|
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
Joined: 24 Jul 2008
Posts: 10
Posted: 2009-06-09 08:47
Back to top
Reply with quote
|
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:
| Quote: |
| 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.
| Code: |
$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
Joined: 10 Feb 2003
Posts: 1013
Location: Denver, Colorado (USA)
Posted: 2009-06-09 20:41
Back to top
Reply with quote
|
I don't think you can user both 'values' and 'values2', so try commenting out:
| Code: |
| $opts['fdd']['member9']['values2'] = array(", " => ""); |
|
foxylady337
Joined: 24 Jul 2008
Posts: 10
Posted: 2009-06-09 23:31
Back to top
Reply with quote
|
I have solved my problem with this code:
| Code: |
$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.
|
|
Post new topic
Reply to topic
|
|