ballhogjoni Posted August 8, 2007 Share Posted August 8, 2007 Ok I am trying to select one record from a database. This databse has like 10 tables. I do not know which table this record is in. What php and mysql syntax would I use to accomplish this? Quote Link to comment https://forums.phpfreaks.com/topic/63970-trying-to-select-one-record-from-a-database/ Share on other sites More sharing options...
teng84 Posted August 8, 2007 Share Posted August 8, 2007 if your saying that you want to find a certain record in 10 table then i guess the only way is to query each table one by one What php and mysql syntax would I use to accomplish this? it will only need the usual way the fetch array and mysql_query Quote Link to comment https://forums.phpfreaks.com/topic/63970-trying-to-select-one-record-from-a-database/#findComment-318869 Share on other sites More sharing options...
ballhogjoni Posted August 8, 2007 Author Share Posted August 8, 2007 this is my code so far: $query = "SELECT `contact_n_questions`.`fname`, `dispo_callBack`.`fname`, `dispo_client`.`fname` FROM contact_n_questions, dispo_callBack, dispo_client WHERE ((`contact_n_questions`.`fname`) OR (`dispo_callBack`.`fname`) OR (`dispo_client`.`fname`)) = '$search_fname'"; $result = mysql_query($query) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/63970-trying-to-select-one-record-from-a-database/#findComment-318874 Share on other sites More sharing options...
ballhogjoni Posted August 8, 2007 Author Share Posted August 8, 2007 How would run a loop with the tables in the db? Would you run a foreach loop? Can you explain that a little more? Quote Link to comment https://forums.phpfreaks.com/topic/63970-trying-to-select-one-record-from-a-database/#findComment-318886 Share on other sites More sharing options...
DjMikeS Posted August 8, 2007 Share Posted August 8, 2007 '$search_fname' The contents of that variable come from ? In other words... did you define it ? and what exactly is going wrong ? Quote Link to comment https://forums.phpfreaks.com/topic/63970-trying-to-select-one-record-from-a-database/#findComment-318887 Share on other sites More sharing options...
teng84 Posted August 8, 2007 Share Posted August 8, 2007 your using a Cartesian join i dont know if thats gonna sort it out but look if you can do a print_r(mysql_fetch_array(' ')) i believe its the same as the usual thing foreach or while but with this question How would run a loop with the tables in the db? i believe you you have to come up with $table = array('table1','table2'); foreach($table as $tbl) { select * from $tbl } [code] although querying for this way may be slower but it will give you an exact ouptu you neeed [/code] Quote Link to comment https://forums.phpfreaks.com/topic/63970-trying-to-select-one-record-from-a-database/#findComment-318897 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.