Vitamin Posted October 23, 2010 Share Posted October 23, 2010 I'm kind of new to database's and how they should work. I have a decent understanding, but I'm working on changing my database from 1 giant table to 3 or 4 different tables. Here is the problem that I have. I have a field in the main table called maps and it used to just hold the map name, but now I want to have a map table and just place the ID of that map in the main table. But now how is the best way to query this table. For example when I request the page it will send me the last 10 results of the main table, but then I want to display the map name on this page, which then I would need to get the ID from the main table and then query the map table. Is that the correct way of doing this? The reason I ask is because every time that page is called it will have to do 11 querrys instead of just the 1 I was doing before. while ($row = mysql_fetch_array($sql)) { //other code $sql2 = mysql_query("SELECT mapname FROM maps WHERE id = '${row['map']}'"); while ($row2 = mysql_fetch_array($sql2)) { echo $row2['mapname']; } } While it used to just be while ($row = mysql_fetch_array($sql)) { //other code echo $row['map']; } Guess I'm just looking for input if this is the correct way of doing it. Quote Link to comment https://forums.phpfreaks.com/topic/216634-database-querys/ Share on other sites More sharing options...
trq Posted October 23, 2010 Share Posted October 23, 2010 There is a tutorial on our main site that covers UNIONS & JOINS, you should read it. Quote Link to comment https://forums.phpfreaks.com/topic/216634-database-querys/#findComment-1125539 Share on other sites More sharing options...
Vitamin Posted October 23, 2010 Author Share Posted October 23, 2010 Ok, thanks! I'll take a look at it. I figured it was more complex then just a right and wrong answer. Quote Link to comment https://forums.phpfreaks.com/topic/216634-database-querys/#findComment-1125540 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.