mysql whats wrong

Status
Not open for further replies.

raimis

Member
Element "Display" eval = yes
why not work, in bookin_15_repeat table i have two rows with same BookID, but if i return without while function get only one number, or with while function i do not get anything

PHP:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select(array('type', 'number'));
$query->from($db->quoteName('bookin_15_repeat'));
$query->where($db->quoteName('parent_id'). " = {BookID}");
$db->setQuery($query);
$result = $db->loadObjectList();
while ($row = mysql_fetch_assoc($result))
{
  return $row['number'];
}

var_dump
Code:
array(2) { [0]=> object(stdClass)#823 (2) { ["type"]=> string(1) "1" ["number"]=> string(11) "TEMU5557376" } [1]=> object(stdClass)#809 (2) { ["type"]=> string(1) "1" ["number"]=> string(11) "TRHU2017336" } }
 
Last edited:
I think that your query not right.
You have error $query->select(array('type', 'number');.
Must be $query->select(array('type', 'number'));
 
Code:
$result = $db->loadResult();
return $result; get only number 1

var_dump
Code:
string(1) "1"

:/ i really not understand this mysql part
 
As in the WIKI
Load a single VALUE from a ROW of data: -> $fieldA=$db->loadResult();

// Load the results as an array of objects.
$rows = $db->loadObjectList();
Returning data from the array of rows (above) and display it
e.g when using a calc element for this purpose? Let's say we want to display the rows as fieldA and fieldB in an ordered list:
PHP:
$list = array();
foreach ($rows as $row)
{
$list[] = "<li>" . $row->fieldA . " " . $row->fieldB . "</li>";
}
return "<ol>" . implode($list) . "</ol>";
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top