December 9, 201114 yr Hi there, im trying to get data from 2 tables, neither have any relativity to the other. i looked into JOIN but as far as i can make out of it, it is joining 2 tables with a field with same data as on another. iv been trying the following: SELECT * FROM _chk_login, _chk_other WHERE _chk_login.email = 'me@place.com' AND _chk_other.place = '2' But when echoing the row in table _chk_login $row['email']; Nothing happens. Any help much appreciated.
December 9, 201114 yr I'm not really sure why you would want to select from two separate tables when they have nothing to do with each other. Can you explain a bit more what you're trying to do? If they don't have any kind of relationship, then you're essentially going to have to do two queries, however this sounds like it could just be a flawed DB design
December 9, 201114 yr Author I'm not really sure why you would want to select from two separate tables when they have nothing to do with each other. Can you explain a bit more what you're trying to do? If they don't have any kind of relationship, then you're essentially going to have to do two queries, however this sounds like it could just be a flawed DB design Okay.. so i have a job site. 1 contains all information about a person, path to resume etc etc. The other database has jobs. I want the person to apply for the job but im trying to echo the resume path while showing the job title applying for.
December 9, 201114 yr Author Sounds like a pretty bad database design to me - always worth taking a step back and looking at your design when you're finding it hard to select basic information. Im using the incorrect terminiology. there 2 TABLES in the same database. If you could help me in how the appropriate database design in this regard should be, that would help a little more.
December 9, 201114 yr Look into 3rd normal form for database design. 3rd Normal Form Perhaps you need a 3rd table where you insert the ID of the person applying and the ID of the job, and any other information you may need. The reason for doing this is you will have more than 1 person applying for each job and it will mean that you are not creating the same data over and over again that is already in the database. Edited December 9, 201114 yr by adamsmith
December 9, 201114 yr Author Look into 3rd normal form for database design. 3rd Normal Form Perhaps you need a 3rd table where you insert the ID of the person applying and the ID of the job, and any other information you may need. The reason for doing this is you will have more than 1 person applying for each job and it will mean that you are not creating the same data over and over again that is already in the database. Sorry, this is how it all is set out at the moment, apologies as i feel iv been too brief. DATABASE TABLEJOBS TABLEUSERS TABLEAPPLICATIONS The jobs are stored in TABLEJOBS The user information stored in TABLEUSERS I want to grab information for the user AND the job being applied for BEFORE inserting ID of job and ID of user in TABLEAPPLICATIONS. My code so far.. function apply_job($id = 'id') { $quad = $_SESSION['id']; $sql = "SELECT * FROM _chk_jobs WHERE jobid = '$id'"; $res = mysql_query($sql) or die(mysql_error()); echo '<div class="welcome">'; while($row = mysql_fetch_assoc($res)){ echo '<h1>Job Application</h1>'; echo 'You are applying for the following job:<br/><br/>Title: <b>' . $row['jobtitle'] . '</b>'; if (!$row['resume']):{ echo 'You do not currently have a CV uploaded.'; } else: { 'Current CV: <a href="/images/profiles/' . $_SESSION['id'] . '/'. $row['resume'] . '';}endif; } echo '</div>'; } $row['jobtitle'] is in TABLEJOBS $row['resume'] is in TABLEUSERS I know the code is a bit messy and im no pro at PHP or MySQL. Im learning as i go. (Makes it easier for me rather than reading before i do it). Hopefully this has cleared things up a little more for you.
December 9, 201114 yr Well you can either do 2 seperate SQL queries, or do 1 query with a UNION ALL operator. Edited December 9, 201114 yr by adamsmith
December 9, 201114 yr Author Using UNION i got the following error: The used SELECT statements have a different number of columns
December 9, 201114 yr Using UNION i got the following error: The used SELECT statements have a different number of columns Sorry that's my mistake. Well as far as I can see there is a couple ways you can go about it. Using 2 SQL queries is perfectly fine, there is nothing wrong with it. Or You could insert the data into the applications table first then do a union select on that table since you will be creating a link between the person and the job. I think you should just stick to using 2 SQL queries though. Are you sure that you aren't calling the same data from another part of the site for the user such as login where you could capture the CV data and maybe store as a SESSION. Then you would only need to use the one query for the job. Edited December 9, 201114 yr by adamsmith
December 9, 201114 yr Author I think you should just stick to using 2 SQL queries though. Are you sure that you aren't calling the same data from another part of the site for the user such as login where you could capture the CV data and maybe store as a SESSION. Then you would only need to use the one query for the job. How would i go about making these 2 queries as im trying but its not going through to the second query in the while loop. (code below). Also. i could store the resume as a session but then if the user has no resume and uploads it, then the user needs to login again for the session resume to appear. function apply_job($id = 'id') { $quad = $_SESSION['id']; $sql = "SELECT * FROM _chk_jobs WHERE jobid = '$id'"; $res = mysql_query($sql) or die(mysql_error()); echo '<div class="welcome">'; while($row = mysql_fetch_assoc($res)){ echo '<h1>Job Application</h1>'; echo 'You are applying for the following job:<br/><br/>Title: <b>' . $row['jobtitle'] . '</b>'; $sql2 = "SELECT * FROM _chk_login WHERE email='$quad'"; $res2 = mysql_query($sql2) or die(mysql_error()); while($row2 = mysql_fetch_assoc($res2)){ if (!$row2['resume']):{ echo 'You do not currently have a CV uploaded.'; } else: { 'Current CV: <a href="/images/profiles/' . $_SESSION['id'] . '/'. $row2['resume'] . '';}endif; } } echo '<a href="/apply_job_done.php?id=' . $row['jobid'] . '">Apply For This Job</a></div>'; } Edited December 9, 201114 yr by Tex0gen
December 9, 201114 yr Well done mate, how did you end up doing it in the end? And just in case anyone else is having this problem, my post number #10 had an error in it that I've just noticed and it won't let me change it... You could insert the data into the applications table first then do a union select on that table since you will be creating a link between the person and the job. should be... You could insert the data into the applications table first then do an inner join on that table since you will be creating a link between the person and the job. Edited December 9, 201114 yr by adamsmith
December 10, 201114 yr Post your database structure - would be useful in getting you a proper answer - by the looks of it, a normal join should be enough. +1 It is always a good thing to post the relevant SQL DDL when asking questions like this.
Create an account or sign in to comment