valedo
Založený: 31.08.2006
Príspevky: 6
Bydlisko: Ukraine
Zaslal: 2006-09-01 22:57
Návrat hore
Odpovedať s citátom
|
Hi everyone!
I am using this code:
$opts['fdd']['articles'] = array(
'name' => 'blablabla',
'select' => 'D',
'maxlen' => 65535,
'values' => array( 'table' => 'Articles_categories', 'column' =>'id', 'description'=>'category', 'orderby' => 'category'),
'sort' => true
);
But, in my drop down list items sorted in return order
Example
9
8
7
etc...
i hack phpMyEdit for Mysql Query, here is :
SELECT DISTINCT Articles_categories.id,Articles_categories.category FROM mydb.Articles_categories ORDER BY category
in this case ORDER BY not work (see http://bugs.mysql.com/bug.php?id=3681)
you can see this "fixed in 4.1.2", but i am using
MySQL - 4.1.21-standard
In any case i found solution:
Mysql Query must be :
SELECT DISTINCT Articles_categories.category,Articles_categories.id FROM mydb.Articles_categories GROUP BY category ORDER BY category
i am not absolutely understanding "GROUP BY" operator but it helps me.
sorry for my bad english)
sorry if I am not right
Naposledy upravil valedo dňa 2006-09-03 05:58, celkom upravené 1 krát
|
michal
Založený: 17.06.2003
Príspevky: 537
Bydlisko: Slovakia
Zaslal: 2006-09-02 13:20
Návrat hore
Odpovedať s citátom
|
just wondering, is distinct there neccessary ? i mean joining should by done to a primary/unique index, because it would fail on the output side anyway.
|
Denver Dave
Založený: 02.02.2003
Príspevky: 19
Zaslal: 2007-06-27 01:42
Návrat hore
Odpovedať s citátom
|
I may have hit the same issue. I have one main table with 2 lookup tables. Everything works when adding records, except the lookup table dropdowns are not sorted.
$opts['fdd']['specialty_ID'] = array(
'name' => 'Specialty',
'select' => 'T',
'maxlen' => 11,
'default' => '0',
'sort' => true,
'values' => array(
'table' => 'specialty',
'column' => 'ID',
'description' => 'name',
'orderby' => 'name'
),
);
I added the orderby above, but it did not seem to have any effect.
On a different server, I had a similar application where the dropdowns were sorted, so I loaded the data on the different server and the application and the dropdowns were sorted properly on the different server. The different server did not accept the latin1 and I'm not sure whether this has anything to do with the problem or not.
I'm thinking about writing out or catching the generated sql for the dropdown boxes on the add record form. Any idea where in phpMyEdit.class.php this might be?
|
Denver Dave
Založený: 02.02.2003
Príspevky: 19
Zaslal: 2007-06-27 05:00
Návrat hore
Odpovedať s citátom
|
I've found the problem, but I'm not sure how to correct it:
The select statement being used by phpMyEdit can easily be viewed by changing the $debug to 1 in the following statement
function myquery($qry, $line = 0, $debug = 0)
SELECT DISTINCT location.ID,location.name FROM info_sma.location ORDER BY name
In phpMyAdmin on my main server, this does not produce a sorted result set. Strangely, on my old server it does.
In my case, the lookups are unique without the ID so the following SQL will produce the result that I want when I eliminate the location.ID field:
SELECT DISTINCT location.name FROM info_sma.location ORDER BY name
I think the issue is in:
function set_values_from_table
but I'm not sure what to change
Naposledy upravil Denver Dave dňa 2007-06-27 16:46, celkom upravené 1 krát
|
Denver Dave
Založený: 02.02.2003
Príspevky: 19
Zaslal: 2007-06-27 06:11
Návrat hore
Odpovedať s citátom
|
Well here is what I changed to get the lookup table values to sort: Is there a better way?
// in function set_values_from_table
//$qparts['select'] = 'DISTINCT '.$table.'.'.$key;
$qparts['select'] = 'DISTINCT ';
// locate: } else if ($desc) {
//$qparts['select'] .= ','.$table.'.'.$desc;
$qparts['select'] .= $table.'.'.$desc;
// locate: while ($row = @mysql_fetch_array($res, MYSQL_NUM)) {
// $values[$row[0]] = $desc ? $row[1] : row[0];
$values[$row[0]] = $row[0];
|
Denver Dave
Založený: 02.02.2003
Príspevky: 19
Zaslal: 2007-06-27 06:46
Návrat hore
Odpovedať s citátom
|
Well shucks... the changes did sort the lookup fields, but now when editing, somehow the existing value is not selected.
..... hmmmmm
I think the issue may be in function htmlSelect
$found = false;
foreach ($kv_array as $key => $value) {
$ret .= '<option value="'.htmlspecialchars($key).'"';
if ((! $found || $multiple) && in_array((string) $key, $selected, 1)
|| (count($selected) == 0 && ! $found && ! $multiple))
{
// NOTE: selected= is set below
$ret .= ' selected="selected"';
$found = true;
}
$strip_tags && $value = strip_tags($value);
$escape && $value = htmlspecialchars($value);
$ret .= '>'.$value.'</option>'."\n";
}
$ret .= '</select>';
|
Denver Dave
Založený: 02.02.2003
Príspevky: 19
Zaslal: 2007-06-27 22:38
Návrat hore
Odpovedať s citátom
|
It looks like there may be a much easier solution to the sorted lookup table issue.
In my case, the purpose of a lookup table is to provide a description (desc) for an ID number lookup. In my lookup tables the description for the ID number is always unique and if it wasn't there really would be more than one record.
... so, I don't really need the SELECT DISTINCT - removing the "DISTINCT" (and leaving a ' ') seems to make everything work in my situation:
$qparts['select'] = ' '.$table.'.'.$key;
//$qparts['select'] = 'DISTINCT '.$table.'.'.$key;
Hope this helps someone else. If you have a better idea or discussion, please post.
|
|
Odoslať novú tému
Odpovedať na tému
|