Jump to content

Selecting info from table1 depending on a record in table2?


thenexthour

Recommended Posts

I have been looking in the MySql Manual but I\'m not quite sure about something so I thought I\'d ask the wonderful people here:

 

I have a database with two tables; data and jobs. The data table has data about the user while the jobs database has all the information about where the user is looking for a job.

 

Users are required to register and be verified but before they verify their information they are able to add data to both tables. I want to exclude data from unverified users when someone searched the site. Because the data table holds all the verification information and I want to search the jobs table I don\'t think a simple \'where\' command will cut it and I\'m fairly new to PHP/MySql. Currently I have this:

 

$sql = \"select * from jobs where name like \'%$job%\';\";

 

That allows me to search the jobs table but it pulls out both verified and unverified user information re: jobs. I know I can add \'where confirmed = 1\' to the command to exclude unverified info but this only works when qwerying the data table, not the jobs table.... Anyone got a suggestion/solution? I\'ll be searching around for a solution and post it here if I find one; thanks in advance for the mySql help!

 

Justin

Link to comment
Share on other sites

Rudy from http://r937.com/ gave me the solution on the DevShed site. I thought I\'d share the solution with anyone who is wondering. Thanks again rudy.

 

select jobs.*

 from jobs 

inner

 join data

   on jobs.something = data.something

where jobs.name like \'%$job%\'

  and data.confirmed = 1



the "something" columns are whatever columns you defined to link the user to her jobs

Link to comment
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.