Reputation: 227
I've been stuck with this problem. I have a form where the user will enter his/her input. Based on that input, a query is done to the database that will return matching results.I t's fairly simple but couldn't find a way to do it. I manage to load the data using loadResult().
But now since I want to load from multiple columns, loadResult() is a no go.
<?php
$db = JFactory::getDbo();
$name = JRequest::getVar('name');
$query="SELECT username FROM jos_users WHERE name='$name'";
$db->setQuery($query);
echo $db->loadResult();
?>
That was my code when I was using loadResult(). No problem.
But now I want to load username and status from the query. How can I do that?
I tried putting in
<?php
$db = JFactory::getDbo();
$name = JRequest::getVar('name');
$query="SELECT username, status FROM jos_users WHERE name='$name'";
$db->setQuery($query);
$db->loadObject($name);
echo "Username : $name->username";
echo "Status : $name->status";
?>
But returns an error.
Upvotes: 0
Views: 1061
Reputation: 16
Your code is supposed to be like this. You have to store return value in a variable and then you can use it. But in your code you are trying to print value with the params send to loadObject method.
<?php
$db = JFactory::getDbo();
$name = JRequest::getVar('name');
$query="SELECT username, status FROM jos_users WHERE id='$name'";
$db->setQuery($query);
$row = $db->loadObject();
echo "Username : $row->username";
echo "Status : $row->status";
?>
Upvotes: 0
Reputation: 12101
Try change:
$db->loadObject($name);
echo "Username : $name->username";
echo "Status : $name->status";
to:
$row = $db->loadRowList();
echo "Username : ".$row['username'];
echo "Status :".$row['status'];
Upvotes: 1