Need help !! Using Concat Function with Posgres and PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sree78
Forum Commoner
Posts: 39
Joined: Tue May 20, 2003 11:38 am

Need help !! Using Concat Function with Posgres and PHP

Post by sree78 »

Hi,

I am new to posgres. I am trying to figure out how to use the concat function for my query as below:-

This query is for a search function which searches employee by their last and first name. The reason why i want to do the concat function is to enable the users to search both first and last name together (with a space). This query works well with mysql but with posgres .. it is showing me and error.. I have tried using the (||) but yet I do get an error. Any help is highly appreciated.


Code: Select all

<?php
$query = "

Select employee.empid, employee.fname, employee.lname, emp_info.phone, department.name
FROM employee, department, emp_info
WHERE lname='$emp' OR fname ='$emp'
OR concat (lname,'',fname) ='$emp'
AND employee.empid = emp_info.empid
AND department.deptid = emp_info.deptid
ORDER by employee.fname

";
?>
$emp
-----

Is the search field name I have given in the form.

Thank You :roll:
junrey
Forum Newbie
Posts: 12
Joined: Thu May 09, 2002 9:53 pm
Location: Cebu, Philippines
Contact:

Post by junrey »

hello,

Code: Select all

<?php
$query = " 

Select employee.empid, employee.fname, employee.lname, emp_info.phone, department.name 
FROM employee, department, emp_info 
WHERE lname='$emp' OR fname ='$emp' 
OR (employee.lname || ' ' || employee.fname) ='$emp' 
AND employee.empid = emp_info.empid 
AND department.deptid = emp_info.deptid 
ORDER by employee.fname 

"; 
?>
i guess that works. but not so sure, i have been using 7.3.1 version of postgresql and having no problem with the double pipe for concat purposes.

Regards.
sree78
Forum Commoner
Posts: 39
Joined: Tue May 20, 2003 11:38 am

Post by sree78 »

Tried the method... it does not produce any error but neither finds any data ...

How do we do a search by allowing spaces in the search box
e.g Joe Smith?

My DB Table
---------------
Fname = Joe
lname = Smith

Code: Select all

<?php
<?php 
$query = " 

Select employee.empid, employee.fname, employee.lname, emp_info.phone, department.name 
FROM employee, department, emp_info 
WHERE lname='$emp' OR fname ='$emp' 
OR (employee.lname || ' ' || employee.fname) ='$emp' 
AND employee.empid = emp_info.empid 
AND department.deptid = emp_info.deptid 
ORDER by employee.fname 

"; 
?>
?>
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Why not explode the $emp variable first and then check the two fields explicity, instead of using concatenation?
Post Reply