gobbles Posted June 26, 2007 Share Posted June 26, 2007 Hey All, Im having some problems with a script of mine. i have one MySQL table that has the value of an account i.e 'Free Account' = $0, 'Basic Account' = $300 .. then i have another table with the account id which would be 'Free Account' or 'Basic Account' and also a paid which is 'Yes' and 'No' How could i combine 2 tables into one search. What i want to do, is check if an account is paid, if the paid column is 'no' then display $0, but if it is 'yes' then check the account id and match it with the account id on the other table and return the value i.e $300 of that account. If that makes sense to anyone, i would really like some help. Cheers. Quote Link to comment Share on other sites More sharing options...
bigbob Posted June 26, 2007 Share Posted June 26, 2007 you would run the query: <?php //Get it from the "SEARCH" form... $accountname = $_POST['account_name']; $result = mysql_query("SELECT * FROM table_name WHERE account_name= '$accountname'"); //Then you would output it in a variable $i = 0; $num = mysql_numrows($result); $accoutname=mysql_result($result, $i,"Account Name"); $paid=mysql_result($result, $i,"Paid"); while ($i < $num) { echo $accountname; echo $paid; } ?> There's a basic listing for a search function Quote Link to comment Share on other sites More sharing options...
gobbles Posted June 26, 2007 Author Share Posted June 26, 2007 Thats just a basic search function. Im talking about a cross table query Quote Link to comment Share on other sites More sharing options...
gobbles Posted June 27, 2007 Author Share Posted June 27, 2007 Im sure theres a left join in there somewhere. Here is the table layout ---------------------------------- | packages | advertisers | ---------------------------------- | id | plan | | price | paid | | | id | | | signup_date | | | venue_name | ---------------------------------- The ID field in the packages table and the PLAN field in the advertisers table are the ones that have the same values. SELECT * FROM both tables where packages.id = advertisers.plan AND paid = YES Thats basically what i need to do If someone could actually put that into a SQL statement, it would REALLY help me out Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted June 27, 2007 Share Posted June 27, 2007 u have to link both tables through id try out this : SELECT * FROM both tables where packages.id = advertisers.id AND paid =YES Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.