I am trying to create a simple fb app that retrieves the name of the user using fql_query.
Code :
require_once 'facebook.php';
$appapikey = 'xxxx';
$appsecret = 'xxxx';
$facebook = new Facebook($appapikey, $appsecret) ;
$user_id = $facebook->require_login();
$q = "SELECT name FROM user WHERE uid='$user_id'";
$name = $facebook->api_client->fql_query($q);
echo "Name : $name[0][name]";
Output:
Name : Array[name]
Can you tell me what's going wrong here?
Thanks!
Mistake is in this line:
echo "Name : $name[0][name]";
you are including $name[0][name] in quotes, this should be
echo "Name : {$name[0][name]}";
or
echo "Name : ".$name[0][name];
An FQL query always returns an array, even if there is only one item in the result. Think of the result as rows in a normal SQL query.
Any time that I use arrays or database/API calls in PHP I print_r($array_name) to see what was returned. So this:
$name = $facebook->api_client->fql_query("SELECT name FROM user WHERE uid=$user_id");
print_r($name);
Should return this:
Array
(
[0] => Array
(
[name] => First Last
)
)
Another thing, I never put tick marks around values/variables in FQL.
$q = "SELECT name FROM user WHERE uid=$user_id";
$name = $facebook->api_client->fql_query($q);
But when you print the value you should put single quotes around the reference to the named index (in this case, 'name') and you should not wrap it all in double quotes:
echo "Name : " . $name[0]['name'];
Related
I have tbl_invoice.first_name and tbl_invoice.last_name as name, so want to search by name in Codeigniter with LIKE.
(example: first_name = Sanjib, last_name = Sarkar, name = Sanjib Sarkar . Search by "Sanjib Sarkar")
$this->db->select('tbl_invoice.*,tbl_members.*');
$this->db->from('tbl_invoice');
$this->db->join('tbl_members', 'tbl_members.id = tbl_invoice.member_id', 'left');
$this->db->like(CONCAT('tbl_invoice.first_name'." ".'tbl_invoice.last_name'), $search_value);
$query = $this->db->get();
Use this code to check value from first and last name using single like query
$this->db->select('tbl_invoice.*,tbl_members.*');
$this->db->from('tbl_invoice');
$this->db->join('tbl_members', 'tbl_members.id = tbl_invoice.member_id', 'left');
$this->db->like("(`first_name` LIKE '%m%' OR `last_name` LIKE '%m%')");
$query = $this->db->get();
I have a database table ("buildings") in MySQL consisting of 3 columns:
Name
Place
Number
I have created a dropdown list in my view page which contains the names of the buildings and also a textarea.
Now, depending on which name the user selects, the textarea should be populated with the respective place and number of the name of the building. I’m able to get the result but I want the output to be more readable. Right now, the format of the output is as:
Array
(
[0] => Array
(
[Number] => 14
[Place] => Cambodia
)
)
Is there anyway I could get the output to be as simple as:
Number : 14
Place: Cambodia
Her's the model code:
<?php
class Application_Model_Building extends Zend_Db_Table_Abstract
{
public function getname($name)
{
$db = $this->getDefaultAdapter();
$auth = Zend_Auth::getInstance();
$select = "SELECT * FROM buildings where name = $name";
$stmt = $db->query($select);
$result = $stmt->fetchAll();
print_r ($result);
}
}
?>
instead of echoing the array dump, try:
foreach ($result as $vals) {
echo "Place: ".$vals["Place"]."<br>Number: ".$vals["Number"];
}
as other posters have commented, you should read about php arrays so you know why this makes sense
I am trying to make a simple Rose DB call:
$id = xyz;
$name = "company";
DataB::testTable::Manager->get_testTable( query =>[ id => $id, name => $name ] );
in it possible to not have the whole query written every time, and declare it like a string variable such that i can just call
DataB::testTable::Manager->get_testTable( query =>[ $query ] );
where $query = qq { id => $id , name => $name };
Please Help
By what I understood from your question, I am giving this answer.
Try this one.
my $myquery = {query =>{ id=>$id, name=>$name }} ;
TGI::testTable::Manager->get_testTable($myquery);
Hope, this gives some idea to you.
Edit for "Hash with Array reference":
my $myquery = [ id=>$id, name=>$name ] ;
TGI::testTable::Manager->get_testTable(query => $myquery);
check out this : How to pass a a string variable as "query" for get Manager call?
Well actually i figured out how to do that . Its not that complicated. Only thing is RoseDB objects expect an array reference for a query. So something like this works :
my #query = ( id => $id, name => $name );
testDB::testTable::Manager->get_testTable( query => \#query );
Just thought would answer it myself, incase someonelse is looking for a solution to this
I have added a field in 'Manage User Fields' & when an email is sent to the administrator notifying them of the new user registration, I want to include this new field.
I have written some code to get this new field from #__vm_user_info in /administrator/components/com_virtuemart/classes/ps_shopper.php, in the _sendMail function, as well as added the variable to $message2.
ASEND_MSG has been modified to accept the parameter, but the field is not included in the email to the admin when a user is created. When I go look in the table, the data is there. So to trouble shoot, I hard coded a user name in the select statement, added another user & the correct value was sent for the hard coded user, not the one just added. I am now thinking that it is a commit issue with MySQL, so I put a sleep(4) in the code before I attempt to get the value...no luck.
Can anyone shine some light on this for me??
LarryR....
administrator/components/com_virtuemart/classses/ps_shopper.php
Need to add with the following code in function add() before "return true" line :
/**************************** ***********************/
$pwd = $_POST['password'];
$db = JFactory::getDBO();
$query = "SELECT id, name, email, username"
. "\n FROM #__users"
. "\n ORDER by id DESC LIMIT 1"
;
$db->setQuery( $query );
$rows = $db->loadObjectList();
$namee = $rows[0]->name;
$emaill = $rows[0]->email;
$usern = $rows[0]->username;
$pwd;
$lid = $rows[0]->id;
$dbv = new ps_DB;
echo $query = "SELECT *"
. "\n FROM #__{vm}_user_info"
. "\n WHERE user_id=$lid"
;
$dbv->setQuery( $query );
$fid = $db->loadObjectList();
$field = $fid[0]->extra_field_1;
$user = clone(JFactory::getUser());
$usersConfig = &JComponentHelper::getParams( 'com_users' );
if ($usersConfig->get('allowUserRegistration') == '0') {
JError::raiseError( 403, JText::_( 'Access Forbidden' ));
return false;
}
// If user activation is turned on, we need to set the activation information
$useractivation = $usersConfig->get( 'useractivation' );
if ($useractivation == '1')
{
jimport('joomla.user.helper');
$user->set('activation', md5( JUserHelper::genRandomPassword()) );
$user->set('block', '1');
}
$component = 'com_user';
$activation_link = $mosConfig_live_site."/index.php?option=$component&task=activate&activation=".$user->get('activation');
$this->_sendMail( $namee , $emaill, $usern, $pwd, $activation_link);
/************************************************** Spinz ********************************************/
Note : Here we created the mail function for username and password to users mail.
administrator/components/com_virtuemart/classses/ps_shopper.php
Need to comment the line in function register_save() before "return true" line:
// Send the registration email
//$this->_sendMail( $name, $email, $username, $password, $activation_link );
Note: Here the mail function generated we need to comment that mail functions and create another mail function in add() function of ps_shopper.php in first point.
administrator/components/com_virtuemart/classses/ps_shopper.php
Need to get the extra added field (extra_field_1) in jos_vm_user_info table in the function _sendmail() with following code and that field sent through the mail to user.
/****************************************************************/
$db = JFactory::getDBO();
$query = "SELECT id, name, email, username"
. "\n FROM #__users"
. "\n ORDER by id DESC LIMIT 1"
;
$db->setQuery( $query );
$rows = $db->loadObjectList();
$lid = $rows[0]->id;
$dbv = new ps_DB;
$query = "SELECT *"
. "\n FROM #__{vm}_user_info"
. "\n WHERE user_id=$lid"
;
$dbv->setQuery( $query );
$fid = $db->loadObjectList();
$field = $fid[0]->extra_field_1;
$subject = sprintf ($VM_LANG->_('SEND_SUB',false), $name, $mosConfig_sitename);
$subject = vmHtmlEntityDecode($subject, ENT_QUOTES);
if ($mosConfig_useractivation=="1"){
$message = sprintf ($VM_LANG->_('USEND_MSG_ACTIVATE',false), $name, $mosConfig_sitename, $activation_link, $mosConfig_live_site, $username, $pwd, $field );
} else {
$message = sprintf ($VM_LANG->_('PHPSHOP_USER_SEND_REGISTRATION_DETAILS',false), $name, $mosConfig_sitename, $mosConfig_live_site, $username, $pwd, $field);
}
/*************************************/
Note :
Initialize the variable "$field" get the extra added field value using query. Then that the extra field value is assigned by message section of the mail.(initialize variable $field having the a value added extra fields in virtuemart).
administrator/components/com_virtuemart/languages/common/english
replace the messages for the following code:
'USEND_MSG_ACTIVATE' => 'Hello %s,
Thank you for registering at %s. Your account is created and must be activated before you can use it.
To activate the account click on the following link or copy-paste it in your browser:
%s
After activation you may login to %s using the following username and password:
Username - %s
Password - %s
Degree - %s'
2.'PHPSHOP_USER_SEND_REGISTRATION_DETAILS' => 'Hello %s,
Thank you for registering at %s. Your customer account has been created.
You may login to %s using the following username and password:
Username - %s
Password - %s
Degree - %s
'
Note:
The extra added values assigned by the string %s in language file.
The message having the string values of extra added field value in virtuemart.
The degree shows the added extra field
I want to get the contents from a row in the Postgresql database and compare the lowercase version of it to a lowercase version of a user input to check if it exists in the database.
i tried:
"SELECT LOWER(name) FROM user_names WHERE name LIKE '%$search%' ORDER BY name ASC"
but that make query not working at all.
EDIT
I am trying to implement an autocomplete Jquery UI like here:
http://jqueryui.com/demos/autocomplete/#remote
for search box (for names)
using javascript and php.
php code:
$search = ($_GET['term']);
if (!$con)
{ die('Could not connect: ' . pg_last_error ());}
else
{
$sql = "SELECT name FROM users_table WHERE name LIKE '%$search%' ORDER BY name ASC";
$result = pg_query($sql);
$json = '[';
$first = true;
while ($row = pg_fetch_array($result))
{
if (!$first) { $json .= ','; } else { $first = false; }
$json .= '{"value":"'.$row['name'].'"}';
}
$json .= ']';
echo $json;
exit();
}
JavaScript code:
$(document).ready(function()
{
$('#auto').autocomplete(
{
source: "./file.php",
minLength: 3
})
})
all above work great.. exactly like in Demo here: http://jqueryui.com/demos/autocomplete/#remote
my problem is that the names in database stored in Uppercase (e.g. LORI)
and of course the user prefers to insert a lowercase in search box to search for name (e.g. lori). but since it stored in uppercase, i need to convert it.
i tried as your suggestion :
$sql = "SELECT LOWER(name) FROM users_table WHERE name ILIKE '%$search%' ORDER BY name ASC";
then i got an empty drop down list!
pretty weird!
thanks in advance.
Google is your friend:
SELECT LOWER(name) FROM user_names
WHERE name ILIKE '%$search%' ORDER BY name ASC