Jump to content

Recommended Posts

I have added search bar to my project and checking multiple criteria through that searching text box. In there, user can enter their searching subject, their searching tutor's name, preferred city or their searching institute.. Then I am getting that searching word into a variable.. it is '$searchString'. Now I need to create a query to display search results... and I tried it like this..

 

$q = "SELECT tcs.tutor_id AS tid, tcs.category_id AS cid, tcs.subject_id AS sid,
               GROUP_CONCAT( DISTINCT s.subjects SEPARATOR ', ') AS subjects,
               t.tutor_name AS tname, t.tutor_code AS tcode, DATE_FORMAT(t.registration_date, '%b %D, %Y') AS date,
               t.qualification AS qualifi,
               GROUP_CONCAT( DISTINCT o.option_name SEPARATOR ', ') AS tutor_option,
               timg.image_name AS img,
               city_name AS city,
               d.district_name AS district
  FROM tutor_category_subject as tcs
  INNER JOIN subject AS s ON tcs.subject_id = s.subject_id
  INNER JOIN tutor_option AS toption ON toption.tutor_id = tcs.tutor_id
  INNER JOIN options AS o ON toption.option_id = o.option_id
  INNER JOIN tutors AS t ON tcs.tutor_id = t.tutor_id
  INNER JOIN address ON address.address_id = t.address_id
  INNER JOIN city ON city.city_id = address.city_id
  INNER JOIN district AS d ON d.district_id = city.district_id
  LEFT JOIN tutor_images AS timg ON timg.tutor_id = tcs.tutor_id AND timg.image_type = 'profile'
  WHERE t.tutor_id IN (SELECT t2.tutor_id
               FROM tutors AS t2
               INNER JOIN tutor_category_subject AS tcs2
               ON tcs2.tutor_id = t2.tutor_id
               JOIN subject AS s2
               ON s2.subject_id = tcs2.subject_id
               WHERE s2.subjects LIKE '$searchSting')
  GROUP BY tcs.tutor_id LIMIT $start, $display";

 

This query is working only if a user is searching a subject. My problem is I need to check if a user is searching a particular tutor by giving a tutor name or searching a city by giving a city name or typing an institute name to search an institute in search text box. So can I know how can I find what is the value $searchString have and how to create the query with this variable value..

 

I tried it with some changing in my sub query's where clause. it is something like this...

 

WHERE (s2.subjects LIKE '$searchSting' OR t.tname LIKE '$searchString' OR city.city LIKE '$seachString')

 

But it is not working.. can anybody help me to fix this problem?

 

Thank you...

Link to comment
https://forums.phpfreaks.com/topic/271193-creating-a-query-with-multiple-criteria/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.