Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/216634-database-querys/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.