? ? Success

User tests: Successful: Unsuccessful:

avatar artur-stepien
artur-stepien
22 Jun 2015

$key is a numeric index of a field in $row array not a field/column name. $row variable is an array indexed starting from zero. So $key is unique . Using column name in this param can result in unexpected results.

Here is a test (put it for example in template's index.php):

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('title,id')->from('#__menu');
$db->setQuery($query);
$results = $db->loadRowList('id');
var_dump($results);die;

This test should return all menu items indexed by item id. But what it does is returning first item in rows list.

The correct code should be a follows:
Here is test:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('title,id')->from('#__menu');
$db->setQuery($query);
$results = $db->loadRowList(1);
var_dump($results);die;

So as you can see description is wrong.

avatar artur-stepien artur-stepien - open - 22 Jun 2015
avatar artur-stepien artur-stepien - change - 22 Jun 2015
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 22 Jun 2015
Labels Added: ?
avatar zero-24 zero-24 - change - 22 Jun 2015
Title
Fixed param description
Wrong loadRowList param description in driver.php
avatar zero-24 zero-24 - change - 22 Jun 2015
Title
Fixed param description
Wrong loadRowList param description in driver.php
Labels Added: ?
avatar zero-24 zero-24 - change - 22 Jun 2015
Category Code style Libraries
avatar artur-stepien
artur-stepien - comment - 22 Jun 2015

Here is a test (put it for example in template's index.php):
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('title,id')->from('#__menu');
$db->setQuery($query);
$results = $db->loadRowList('id');
var_dump($results);die;

This test should return all menu items indexed by item id. But what it does is returning first item in rows list.

The correct code should be a follows:
Here is test:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('title,id')->from('#__menu');
$db->setQuery($query);
$results = $db->loadRowList(1);
var_dump($results);die;

So as you can see description is wrong.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/7239.

avatar artur-stepien artur-stepien - test_item - 22 Jun 2015 - Not tested
avatar artur-stepien artur-stepien - change - 22 Jun 2015
The description was changed
avatar izharaazmi
izharaazmi - comment - 29 Jun 2016

But what it does is returning first item in rows list.

Wrong! It returns last item in rows list (every subsequent item overwrites previous item) with an empty index and PHP Notice.

Notice: Undefined index: id in /Users/Izhar/Sites/staging/libraries/joomla/database/driver.php on line 1809

Array
(
    [] => Array   // <== see the empty index created from $row['id']
        (
            [0] => com_patchtester
            [1] => 102
        )
)
avatar izharaazmi
izharaazmi - comment - 29 Jun 2016

I'd suggest also rename the parameter $key to $index that hints to be integer.

and change the code inside something like:

while ($row = $this->fetchArray($cursor))
{
    // Ignore if the specified offset does not exist
    if (!isset($index))
    {
        $array[] = $row;
    }
    elseif (isset($row[$index]))
    {
        $array[$row[$index]] = $row;
    }
}
avatar roland-d
roland-d - comment - 3 Nov 2016

Hello @artur-stepien

Thank you for your contribution.

The last comment here was on June 29th. Can you follow up on the feedback?

Thanks for understanding!


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/7239.

avatar artur-stepien
artur-stepien - comment - 22 Nov 2016

I stopped supporting this repository long a go as you can see, thats why didn't respond faster. The description on this PR is still right. Test is still working on 3.6.4 so $key is basically a numeric index of a column in the single result row. The description of this $key parameter did changed in the core but is still unclear so as the one from my PR. Its possible that PR should be recreated and new better description prepared.

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 11 Mar 2017

any Comment on this PR by Maintainers?

avatar izharaazmi
izharaazmi - comment - 11 Mar 2017

IMO, The note should stay, and yes the parameter type should be integer. String type applies for fetchAssoc method.

avatar photodude
photodude - comment - 22 Mar 2017

@mbabker @csthomas @rdeutz any thoughts on this?

avatar csthomas
csthomas - comment - 22 Mar 2017

This query works ok in all databases:

$query->clear()->select($db->quoteName('id', '1'))->select($db->quoteName('title', '1'))->from('#__menu');
echo count($db->setQuery($query)->loadRowList(0)); // 129 - testing data

But this returns less rows:

$query->clear()->select($db->quoteName('title', '1'))->select($db->quoteName('id', '1'))->from('#__menu');
echo count($db->setQuery($query)->loadRowList(0)); // 121 - testing data

IMO Note mentions about unique values in $key column. Not unique name of column.

avatar artur-stepien
artur-stepien - comment - 23 Mar 2017

I just checked this and in 3.6.5 and it STILL has wrong description (I also used the test method provided in the ticket). It doesn't matter what this function returns when you provide wrong parameter. Only matter what SHOULD be provided as a parameter and how it is described in the function comment. As for now the parameter is a numeric index of a column in a single result. Not a KEY (that suggests a column name). I have no idea why it takes you so long to change one description and how is that even possible that no one tried to check if I'm right.

avatar csthomas
csthomas - comment - 23 Mar 2017

About @param you are right. You may also change variable name $key to $index if you wish.
About Note for me it should stay as I explained it above.

I will mark it as a successful test if you revert Note.

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 7 Apr 2017

@artur-stepien any Response on @csthomas' suggestion?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/7239.

avatar artur-stepien
artur-stepien - comment - 8 Apr 2017

Updated. Can we finally close it? It's over 2 years for closing a simple description change ...

avatar csthomas csthomas - test_item - 8 Apr 2017 - Tested successfully
avatar csthomas
csthomas - comment - 8 Apr 2017

I have tested this item successfully on adce9ee

Code review


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/7239.

avatar dgt41 dgt41 - test_item - 8 Apr 2017 - Tested successfully
avatar dgt41
dgt41 - comment - 8 Apr 2017

I have tested this item successfully on adce9ee


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/7239.

avatar dgt41 dgt41 - change - 8 Apr 2017
The description was changed
Status Pending Ready to Commit
avatar joomla-cms-bot joomla-cms-bot - edited - 8 Apr 2017
avatar dgt41
dgt41 - comment - 8 Apr 2017

RTC, finally
@artur-stepien thanks for your patience on this one

avatar rdeutz rdeutz - change - 10 Apr 2017
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2017-04-10 15:02:04
Closed_By rdeutz
Labels Added: ?
avatar rdeutz rdeutz - close - 10 Apr 2017
avatar rdeutz rdeutz - merge - 10 Apr 2017

Add a Comment

Login with GitHub to post a comment