Results 1 to 5 of 5

Thread: problems with coding list from mysql

  1. #1
    Download 09 FTW TiMeZeRo's Avatar
    Join Date
    Aug 2005
    Location
    Cambridge, UK
    Posts
    831
    Thanks
    0
    Thanked
    1 time in 1 post

    problems with coding list from mysql

    im trying to create a page on my website to list beers that have been on at my local pub

    i want to create a mysql database that is similar to this

    ID l Brewery l Beer l
    1 l Potbelly l Potbelly best l
    2 l Oakham l JHB l

    i want the page to pull the data from the mysql table and list it as follows

    Brewery
    - Beer 1
    - Beer 2
    - Beer 3

    Brewery 2
    - Beer 1
    - beer 2

    basically i want all the beers by the brewery under the brewery name
    if possible id like everything alphabetically ordered or ordered by the brewerys with the most beer but i am havin huge problems coding this as im a slight novice when its comes to making lists and pulling data from the mysql database

    any suggestions would be greatly appreaciated

    one other question dependin on how its done will it matter if for exmaple one brewery has beers wiht ids 3 , 46 , 107 or will they have to be 2,3,4,5,6
    EVE - Online ( TiMeZeRo225, Proper Emo, Facter )
    World of Warcraft:
    Eu:The Shattar ( TiMeZeRo )
    Eu:Shattered halls (Pakapunch, Sigari, Eitu)
    CS:S - TiMeZeRo

  2. #2
    Registered+
    Join Date
    Jun 2010
    Posts
    76
    Thanks
    34
    Thanked
    0 times in 0 posts

    Re: problems with coding list from mysql

    The ID numbers won't matter what they are. As for this list is it that you want the data from the mysql sorted into a html table with one html table per brewery?

    so on the web page something like...
    ______________
    |Brewery A |
    |_____________|
    | Beer 1 |
    |_____________|
    | Beer 2 |
    |_____________|


    ______________
    |Brewery B |
    |_____________|
    | Beer 1 |
    |_____________|
    | Beer 2 |
    |_____________|

    What is the language you're using for your website?

  3. #3
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,048
    Thanks
    1,016
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable

    Re: problems with coding list from mysql

    Use two separate queries, you should be able to do this in two for/list loops.

    So entering the first loop you query MySQL to SELECT Brewery FROM mmmmbeer;, and use the Brewery string to match the beers for that brewery in the proceeding sub-loop with something like SELECT Beer FROM mmmmbeer WHERE Brewery = '$Brewery[i]'.

    You should be able to figure it out from there.
    Quote Originally Posted by Agent View Post
    ...every time Creative bring out a new card range their advertising makes it sound like they have discovered a way to insert a thousand Chuck Norris super dwarfs in your ears...

  4. #4
    Download 09 FTW TiMeZeRo's Avatar
    Join Date
    Aug 2005
    Location
    Cambridge, UK
    Posts
    831
    Thanks
    0
    Thanked
    1 time in 1 post

    Re: problems with coding list from mysql

    smush im coding in php thanx for the advise aidanjt ill look into it and try and get it to list them nice thanx guys
    EVE - Online ( TiMeZeRo225, Proper Emo, Facter )
    World of Warcraft:
    Eu:The Shattar ( TiMeZeRo )
    Eu:Shattered halls (Pakapunch, Sigari, Eitu)
    CS:S - TiMeZeRo

  5. #5
    Not a good person scaryjim's Avatar
    Join Date
    Jan 2009
    Location
    Gateshead
    Posts
    15,196
    Thanks
    1,231
    Thanked
    2,291 times in 1,874 posts
    • scaryjim's system
      • Motherboard:
      • Dell Inspiron
      • CPU:
      • Core i5 8250U
      • Memory:
      • 2x 4GB DDR4 2666
      • Storage:
      • 128GB M.2 SSD + 1TB HDD
      • Graphics card(s):
      • Radeon R5 230
      • PSU:
      • Battery/Dell brick
      • Case:
      • Dell Inspiron 5570
      • Operating System:
      • Windows 10
      • Monitor(s):
      • 15" 1080p laptop panel

    Re: problems with coding list from mysql

    aidanjt's method will work nicely but require quite a lot of calls to the database: shouldn't be an issue but possibly not the most effective way to do it. You could run a single query ordered by brewery then beer, and then step through the single table checking the value of brewery on each step - when it changes you stop the current list, start a new one, then carry on listing beers.

    Quote Originally Posted by TiMeZeRo View Post
    ... if possible id like everything alphabetically ordered or ordered by the brewerys with the most beer ...
    If you use aidanjt's multiple query technique, you can a list of breweries ordered by number of beers using this query:
    Code:
    SELECT Brewery, COUNT(*)
    FROM beerstable
    ORDER BY COUNT(*) DESC
    And I'd strongly recommend using stored procedures / prepared queries if your version of PHP / MySQL supports it (if you're using any recent version it should). While the data stuff you're doing with this shouldn't pose a security risk (as you'd be building your new query using results from your database), it will get you into good habits if you ever want to process user input through your database

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Geforce 6600GT AGP problems? Try this...
    By Mutley in forum Graphics Cards
    Replies: 33
    Last Post: 09-02-2008, 10:28 AM
  2. Choosing a motherboard from this list?
    By Shark00nPT in forum PC Hardware and Components
    Replies: 14
    Last Post: 21-09-2007, 04:33 PM
  3. Real problems with XFX GeForce 6600GT AGP
    By Mutley in forum Graphics Cards
    Replies: 17
    Last Post: 06-05-2007, 01:15 AM
  4. USB device problems on A8N-SLi
    By crossy in forum Help! Quick Relief From Tech Headaches
    Replies: 4
    Last Post: 17-06-2006, 12:07 PM
  5. Problems with new machine
    By kasavien in forum SCAN.care@HEXUS
    Replies: 5
    Last Post: 31-01-2006, 01:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •