ted_chou12 Posted January 11, 2007 Share Posted January 11, 2007 to be clear, I have to tables. one called userinfo, and one is called usercus, however, I can only do one select query, like below:SELECT * FROM userinfo $where$where is not important, its just a mess of different query factors of a customize search, but my real problem is about my other table, usercus, it has a column called photo, however, this search requires the information of that column, how can I do one query that involves the information of that table?ThanksTed Quote Link to comment https://forums.phpfreaks.com/topic/33720-mysql-search-again-but-different/ Share on other sites More sharing options...
HuggieBear Posted January 11, 2007 Share Posted January 11, 2007 If the database is designed well, then the tables should be linked in some way. So they should have a column in each table with related data. Than you can use a SQL join.Do you have one?RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33720-mysql-search-again-but-different/#findComment-158106 Share on other sites More sharing options...
ted_chou12 Posted January 11, 2007 Author Share Posted January 11, 2007 you mean the username? because I setup both a username column for each of the two tables. Quote Link to comment https://forums.phpfreaks.com/topic/33720-mysql-search-again-but-different/#findComment-158110 Share on other sites More sharing options...
ted_chou12 Posted January 11, 2007 Author Share Posted January 11, 2007 this is roughly how my query looks like:SELECT * FROM userinfo WHERE username like '%$user%' AND gender='$gender'so how would I add AND from the usercus photo column?Thanks Quote Link to comment https://forums.phpfreaks.com/topic/33720-mysql-search-again-but-different/#findComment-158115 Share on other sites More sharing options...
HuggieBear Posted January 11, 2007 Share Posted January 11, 2007 Yes, the username is a good example, so your query would look something like this...[code]<?php$sql = "SELECT i.*, p.photo FROM userinfo i, usercus p WHERE i.username = p.username AND i.username LIKE '%$user%' AND i.gender = '$gender'";?>[/code]This is assuming that your username column is related in both tables and that your photo column is in the usercus table and the gender column is in the userinfo table.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33720-mysql-search-again-but-different/#findComment-158120 Share on other sites More sharing options...
ted_chou12 Posted January 11, 2007 Author Share Posted January 11, 2007 yes, your assumption is corret, I will try it immediatly. Quote Link to comment https://forums.phpfreaks.com/topic/33720-mysql-search-again-but-different/#findComment-158127 Share on other sites More sharing options...
ted_chou12 Posted January 11, 2007 Author Share Posted January 11, 2007 how to echo $row? I find some difficulties doing that.... Quote Link to comment https://forums.phpfreaks.com/topic/33720-mysql-search-again-but-different/#findComment-158132 Share on other sites More sharing options...
HuggieBear Posted January 11, 2007 Share Posted January 11, 2007 Ted, if you don't know what fields are called then always print the contents of the array out...[code]<?php// Set the code and query the database$sql = "SELECT i.*, p.photo FROM userinfo i, usercus p WHERE i.username = p.username AND i.username LIKE '%$user%' AND i.gender = '$gender'";$result = mysql_query($sql) or die(mysql_error());$row = mysql_fetch_array($result);// Echo the array to see what the columns are called...echo "<pre>\n";print_r($row);echo "</pre>\n";?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33720-mysql-search-again-but-different/#findComment-158137 Share on other sites More sharing options...
ted_chou12 Posted January 11, 2007 Author Share Posted January 11, 2007 thanks. Quote Link to comment https://forums.phpfreaks.com/topic/33720-mysql-search-again-but-different/#findComment-158140 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.