Postgresql lowercase to compare data - postgresql

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

Related

MOODLE - Portable Document Format

Looking for download (PDF, CSV) the data from moodle custompage. Are there API function, need to call for downloading the data from custompage. The custompage has a table data:
custompage
$table = new html_table();
$table->head = array('course', 'users');
$table->attributes['class'] = 'table';
$sql = "SELECT c.fullname, count(cc.userid) AS 'completed'
FROM {course_completions} cc JOIN {course} ON c.id = cc.course WHERE cc.timestarted > 0
GROUP BY c.fullname ";
$mds = $DB->get_records_sql($sql);
foreach ($mds as $m) {
$table->data[] = new html_table_row(array(implode(array($m->fullname. $m->lastname)),
$m->completed ));
}
echo html_writer::table($table);
For a basic PDF
require_once($CFG->libdir . '/pdflib.php');
$doc = new pdf();
$doc->AddPage();
$output = html_writer::table($table);
$doc->writeHTML($output);
$doc->Output('filename.pdf');
There is a better example in the Moodle source here - /lib/tests/other/pdflibtestpage.php
For CSV
require_once($CFG->libdir . '/csvlib.class.php');
csv_export_writer::download_array('filename.csv, $mds);
Both of the above should be before printing anything to the screen so they are downloaded.
Also in your SQL, you should use GROUP BY c.id because the course fullname isn't unique.

how to use conact in like query in ci

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();

Translation in extension fails when not logged into backend

I have an extbase extension that translates some variables on pages using this
if (is_array($row) && $row['sys_language_uid'] != $GLOBALS['TSFE']->sys_language_content && $GLOBALS['TSFE']->sys_language_contentOL) {
$row = $GLOBALS['TSFE']->sys_page->getRecordOverlay($table, $row,$GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL);
}
But there's a strange bug. It only works, when I'm logged into the backend. As soon as I log out, I can only see the default language.
Using Typo3 8.7
Any ideas what this could cause?
This can happen if you have config.sys_language_overlay = 0 defined globaly on your page object within your Typoscript Setup.
There is a ticket entry in the Typo3 Forge that goes a bit deeper as to why this happens and provides some workarrounds if you need those.
So, I didn't figure out what the problem was, but found my own workaround for the problem. Here's the updated Code:
$table = 'tx_myExt';
$query = "SELECT * FROM ".$table." WHERE pid=".$pid;
$query .= ' AND (sys_language_uid IN (-1,0) OR (sys_language_uid = ' .$GLOBALS['TSFE']->sys_language_uid. ' AND l10n_parent = 0))';
$query .= " AND deleted=0 AND hidden=0";
$res = $GLOBALS['TYPO3_DB']->sql_query($query);
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
//localization
// check for language overlay if:
// * row is valid
// * row language is different from currently needed language
// * sys_language_contentOL is set
if (is_array($row) && $row['sys_language_uid'] != $GLOBALS['TSFE']->sys_language_content && $GLOBALS['TSFE']->sys_language_contentOL) {
$query2 = "SELECT * FROM ".$table." WHERE pid=".$pid;
$query2 .= ' AND sys_language_uid = ' .$GLOBALS['TSFE']->sys_language_content;
$query2 .= ' AND l10n_parent = ' . $row['uid'];
$query2 .= " AND deleted=0 AND hidden=0";
$res2 = $GLOBALS['TYPO3_DB']->sql_query($query2);
$row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res2);
//$row = $GLOBALS['TSFE']->sys_page->getRecordOverlay($table, $row,$GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL);
}
}
So, instead of using getRecordOverlay I'm just repeating the query, accessing the translated record directly. I did read somewhere that this is bad practice, but hey, it works for now, that's all that matters ;)
Still, if someone finds a solution to the original problem, I'd be happy to see that.

Virtuemart / User Fields

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

fql_query returns "Array" instead of name

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'];