Forums

Please Help :SQL Query

akram3035 30 Aug, 2011
Hi iam trying to get a query from sql in the form submit page, but the query is not connected to the fom table but from other table.

i was adding custom code in the submit section with this code which is not working !!

<?php
$db =& JFactory::getDBO();
$query = "
  SELECT *
    FROM `#__users`
    WHERE id = 42
";
$db->setQuery($query);

echo $query;
?>


so please can i know where is the mistake?
thanks so much in advance
pcheng 30 Aug, 2011
I am not sure if this is a mistake but you are doing
echo $query
which is just the string with the query.

If you want the result of the query you should put something like
$data = $db->loadObjectList();
echo $data;


Pericles
GreyHead 30 Aug, 2011
Hi akram 3035,

pericles is correct.

Though you don't need to write a query to get information from the jos_users table. You can use
$some_user =& JFactory::getUser(42);
echo $user->email;
. . .


Bob
This topic is locked and no more replies can be posted.