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. Link to comment https://forums.phpfreaks.com/topic/57263-query-problem/ 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 Link to comment https://forums.phpfreaks.com/topic/57263-query-problem/#findComment-283056 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 Link to comment https://forums.phpfreaks.com/topic/57263-query-problem/#findComment-283061 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 Link to comment https://forums.phpfreaks.com/topic/57263-query-problem/#findComment-283818 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 Link to comment https://forums.phpfreaks.com/topic/57263-query-problem/#findComment-283819 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.