Jump to content

wickning1

Members
  • Posts

    405
  • Joined

  • Last visited

    Never

Everything posted by wickning1

  1. Let's say for instance that the ZipInfo table is storing states: 1 -> Texas 2 -> Iowa 3 -> California You can insert data into the ZipCodes table to look something like this: 78655 -> 1 78666 -> 1 50322 -> 2 90210 -> 3 now because 78655 and 78666 are both pointing to 1, and 1 is pointing to Texas, you know that both 78655 and 78666 are in Texas. But the word "Texas" is only in the database once. This is called normalizing your data and is generally good design. As far as SQL to get the data out, you need to join the tables together. For this database, it'd be something like: SELECT i.state, c.zip FROM ZipCodes c, ZipInfo i WHERE c.infoid=i.id
  2. I'm sorry I don't have much time to explain but here's a rough idea of how I would determine the groups. Maybe it'll be a useful starting point for you. Note that I have my own quick version of doing a mysql query, using $db->get() isn't going to work for you, but it should be clear what it's supposed to do for me. [code] <?php $i = 0; $oldmw = 0; $count = $db->get("SELECT COUNT(*) FROM wrestlers"); while (count($used) <= $count) {     $oldmw = $minw;     $minw = $db->get("SELECT MIN(weight) FROM wrestlers WHERE weight > $oldmw");     $group = $db->getall("SELECT * FROM wrestlers WHERE weight < $minw * 1.10 AND weight > $oldmw");     echo "Group $i";     foreach ($group as $wrestler) {         echo $wrestler['Fname'] . " " . $wrestler['Lname'] . "<br>\n";     }     $i++; } ?> [/code]
  3. Putting in more zip codes with comma separation is a very dirty solution. The "correct" way to solve your problem is to use two tables: ZipInfo (id, whatever, info, you, have) ZipCodes (zip, infoid) Where infoid maps to an id in ZipInfo. This way an infinite number of zip codes can point at the info in one row of ZipInfo. With this structure you can also have a single zip code point to multiple rows of ZipInfo. To avoid this, make zip your primary key (enforces uniqueness).
  4. You are looking for two independent grouping actions. You need to use a sub-query. Try this: SELECT s.raid_id, s.raid_name, s.raid_date, s.raid_note, s.raid_value, s.total, sum( i.item_value ) AS items FROM ( SELECT r.raid_id, r.raid_name, r.raid_date, r.raid_note, r.raid_value, sum( r.raid_value ) AS total FROM eqdkp_raids r JOIN eqdkp_raid_attendees a USING ( raid_id ) GROUP BY r.raid_id ) s JOIN eqdkp_items i USING (raid_id) GROUP BY s.raid_id ORDER BY s.raid_date DESC LIMIT 0 , 50
  5. Any open connections are closed when the PHP script finishes its execution. There is no need to disconnect, the ability is only there for people who need to free up resources ASAP. New database connections are costly in high-performance situations but insignificant for most people. Don't worry about it until you have more experience.
×
×
  • 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.