Jump to content
xisto Community
nightfox1405241487

MySQL, Multiple Tables

Recommended Posts

please try this one instead..

 

SELECT *FROM users uJOIN content cWHERE `u`.`access_name` = \""  . $active_user. "\"AND `u`.`id` = `c`.`id`

the changes are in the quotes..

 

\"" . $active_user. "\"

 

plus this typo

 

`c`.`id`

 

i hope this will work now

Share this post


Link to post
Share on other sites

grrr...

 

now it is giving me Parse error: parse error, unexpected T_VARIABLE for line 18... guess which line that is :D

 

as for the code, I'm assuming it is supposed to be like this:

$sql = "SELECT *	   FROM users u	   JOIN content c	   WHERE `u`.`access_name` = \""  . $active_user. "\"	   AND `u`.`id` = `c`.`id`"

I think that section just needs to be tweaked and then it should work... this script is really starting to get annoying and I'm tempted to put it all into one table...

 

UPDATE: I GOT IT TO WORK!!!

 

Well, I cheated... I took the semi-long-and-not-nearly-effective way to do it... here's what I did:

$sql = "SELECT * FROM users WHERE `access_name` = \""  .$active_user. "\"";$row = mysql_fetch_array(mysql_query($sql));$user_id = $row['id'];$sql2 = "SELECT * FROM content WHERE `cid` = \""  .$user_id. "\"";$row2 = mysql_fetch_array(mysql_query($sql2));
As you can see, since I called up one query which has the User ID number in it and then turned that number into a variable to link the two databases... ;) now I can get on with my life. But still, I'd like to take the old code and get that to work.

 

[N]F

Edited by nightfox (see edit history)

Share this post


Link to post
Share on other sites

Also have you considered using $_REQUEST? Instead of $_POST or $_GET, I'm pretty sure it handles both and I have been using it for some time without fail :D

Share this post


Link to post
Share on other sites

Also have you considered using $_REQUEST? Instead of $_POST or $_GET, I'm pretty sure it handles both and I have been using it for some time without fail :D


I personally avoid to use $_REQUEST; superglobal, but I know quite a lot of people who like to use it, so I guess it is alright, but it can make problems in your script, because I never trust user coming information into my script, so knowing through which method it came is quite alright, especially if you use both methods, but for some time now I really like to use QUERY_STRING with which you get the string index.php?string and even better PATH_INFO, with which you can get the string which comes from /index.php/string, but eventually I don't have anything against $_REQUEST; I just avoid it ;)

Share this post


Link to post
Share on other sites

as for the code, I'm assuming it is supposed to be like this:

$sql = "SELECT *	   FROM users u	   JOIN content c	   WHERE `u`.`access_name` = \""  . $active_user. "\"	   AND `u`.`id` = `c`.`id`"

yeah, you are rigth.. i just posted the query.. :D
i was so sleepy when i do that and lazy tooo...

$sql = "SELECT *	   FROM users u	   JOIN content c	   WHERE `u`.`access_name` = \""  . $active_user. "\"	   AND `u`.`id` = `c`.`id`";

there is a semicolon at the end.. and the parse error is that it is suppose to inside a quote string variable..

--------

They told me this when I started..
Good programmers -- modular / Object oriented approach of programming..
Good programmers -- reuses well crafted codes as libraries..
Good programmers -- have less work to do..
Good programmers -- turns into lazy people..

I guess i put much more focus on the lazt stuff. maybe if i was lazy enough i can be a good programmer..

Share this post


Link to post
Share on other sites

i hope you wont get as lazy as i am..darn.. i think i misunderstood a line or two of that saying..------if something is hard to do..then it is not worth doing it.. LOL

Share this post


Link to post
Share on other sites

its great site to help us

MySQL, Multiple Tables

 

All you have done a grate job for mysql users like us ... Thanks.

Share this post


Link to post
Share on other sites

Retrieving Data from Multiple Table

MySQL, Multiple Tables

 

Table1

Id

Full_name

 

Table2

Id

Contact_address

 

Table3

Id

Products

 

Query option as below

I want to search

? full_name <>

? contact_address <>

? products <>

 

But record in the format of

 

Id | full_name | contact_address | products

 

 

Please help me the good performance tunning codes. (database in mysql and script language is PHP)

 

Thanks!

 

-question by Krishna Aryal

Share this post


Link to post
Share on other sites
Multiple tables in MySQLMySQL, Multiple TablesReplying to nightfoxIn the database I worked on in the 1960s things were so much easier - We just created a field name in the global dictionary that could directly accessa field from another table. -reply by Leon Wooldridge

Share this post


Link to post
Share on other sites
get data from two tables plz plz help meoutMySQL, Multiple Tables

I need to write a query which get array of data from one table and then search in second table at basis of result..Please help me..I can forward my code its only return me one record and search that one rec in second table ..I wanna get  more then one rec Please Please Please help me out..

$show_months5="select * from job_application where email='$email'";Echo "select * from job_application where email='$email'";           $result5=mysql_query($show_months5);             $get_array5=mysql_fetch_array($result5);                     $month5=$get_array5['job_id'];                   $show_month_inf="select * from job where job_id='$month5'";               echo "select * from job where job_id='$month5'";         $result1=mysql_query($show_month_inf);

-question by moon

Share this post


Link to post
Share on other sites
Joins between many to many relationshipsMySQL, Multiple Tables

Hi Guys,I'm struggling to understand the Join statements - I've seen manyExamples of the Joins between one to many - many to one relationships -But none with many to many - where we have one main table - joint table- lookup table.I would most probably do it this way:SELECT * FROM shoes AS sh, colours AS col, shoes_colurs AS shcWHERE sh.Id = shc.Shoe AND col.Id = shc.Colour ORDER BY sh.Name ASCNow - it would obviously work fine, but the question is - is there a better approach - using perhaps JOIN statement?This is very simple statement - but I have one which is referringTo a larger number of the joint tables as one entity can have more manyTo many relationships - and this kind of approach can generate quiteLong statement - this is why I'm wondering if there's a better approachTo this one.Your help would be appreciated.

-reply by Mark

Share this post


Link to post
Share on other sites
how to create the query and scriptMySQL, Multiple Tables

Hi:

Am not learning php and need help at the moment am stuck. I want to post some records. I have option button to determine the data entry: ie. (teacher,doctors,watchman) as the option to determine the charges for (food, transport, allowance) each on selected option to update the revant

tables( table_worker) having attributes (1d,(1,2,3)), name(teacher,doctors,watchman)

table ( table_charges ) having attributes (1d,(1,2,3)),type(food, transport, allowance),name_id from tble_worker(teacher,doctors,watchman).

Can someone help come up with that script for me especially for updating the database and laiter display it as an article

thanks

-question by paul

Share this post


Link to post
Share on other sites
joins/dynamic reportsMySQL, Multiple TablesI throw myself at the mercy of the wise...Please not I am simplifying as much as possible...I have a mysql databsae with three tables; "Districtoffices", "localoffices", and "individuals". For example, "we" might want to do an ad hoc query page where the user can select whatever fields they want from the "localoffices" table and print a report. Two of the fields involved could be the first and last names of the plant manager. Let's assume that the report needs to contain the email address of the plant manager. This is pulled from the "individuals" table.Another example might be to pull a report of all individuals who have a PhD (from the individuals table), and join the office address and phone number from the "localoffice" table based on the person being listed in the "localoffice" table as manager.Hard coding these would be easy - a simple join, but the issue is that I have no control over which of the 30+ fields (per table) the user may want to join into a single report.I am not including any sample code as I have tried so many methods and nothing has goten me close...This issues has caused me to miss a deadline, my hair to turn grey, my liver to become pickeled and my love life to sufer.Any advice?In_a_bind(a newbie programmer with a sence of humor, despite being in deep do-do)-question by in_a_bind

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.