#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    85
    Rep Power
    2

    MySQL Query to an Array


    I am trying to display information in an array from a MySQL query. I am aware that my queries are depreciated.

    PHP Code:
    <?php

    include('connect.php');

    function 
    getControlPointStats() {
        
    $query mysql_query("SELECT * FROM thetable") or die(mysql_error());

        while(
    $row mysql_fetch_array($query)) {
            foreach ( 
    $row as $data ) {
                echo 
    $data['Username'];
            }
        }


    }
    When I go to this page that uses this function I get this, which is not what I am trying to get.

    Code:
    ZZ1111000000000000110011000000000000000000wwssyy1166111111110011110011000000000000000000wwssii1122115511114455110011000000000000000000ssssGG1111000000000000110011000000000000000000wwssaa1166113388220000110011000000000000000000wwssdd1111666644441111110011000000000000000000aassss1133443333221155110011000000000000000000ssssTT1133226633224499110011000000000000000000aaddCC1166663366220011110011000000000000000000mmss771166114455220011110011000000000000000000wwssss1155221111110000110011000000000000000000mmsskk1133119933119933110011000000000000001100ssaagg1111000000330000110011000000000000000000wwssTT1111558822110011110011000000000000000000wwsscc1111221122770022110011000000000000000000nnssNN1166334466111100110011000000000000000000wwssrr1122114411772211110011000000000000000000ssssbb1199554422770011110011000000000000000000wwssLL1166553344771100110011000000000000000000wwssTT1155222288770011110011000000000000000000wwssBB1133110055550000110011000000000000000000wwsspp1111000000000000110011000000000000000000wwssMM1155111188110011110011000000000000000000mmssbb1144112222880011110011000000000000000000wwssMM1166223399110011110011000000000000000000aassJJ1155221199880011110011000000000000000000wwsscc1111000000000000110011000000000000000000wwssUU1133555522116677110011000011000000000000aassKK1122110033880011110011000000000000000000wwssjj1111441188661155110011000000000000000000ssddBB1111221144441133110011000000000000000000aasscc1122110033550000110011000000000000000000wwssSS1111112211111155110011000000000000000000ddddAA1122552211112255110011000000000000000000ssssCC1199114411111100110011000000000000000000aassSS1144111155110011110011000000000000000000aassaa1166223399110011110011000000000000000000aassEE1111000000000000110011000000000000000000wwssbb1111000000000000110011000000000000000000wwssnn1111771144332200110011000000000000000000wwssSS1155111199110011110011000000000000000000aassnn1188114411221111110011000000000000000000ssssMM1111000000000000110011000000000000000000wwssmm1111119911110033110011000000000000000000ssssNN1133111133660000110011000000000000000000wwssnn1122112211114400110011000000000000000000ssddss1111000000000000110011000000000000000000wwssbb1133110066110000110011000000000000000000wwssoo1111441144551100110011000000000000000000ddssLL1111669966112211110011000000000000000000ddddHH1111440011770000110011000000000000000000wwssSS1111113333660022110011000000000000000000wwssvv1111332222770022110011000000000000000000ddssgg1111661155441122110011000000000000000000ssssHH1111440011110000110011000000000000000000wwssNN1155661199220011110011000000000000000000wwssee1111331177110055110011000000000000000000ssssCC1111000000000000110011000000000000000000wwsscc1111000000000000110011000000000000000000wwssaa1111550000000011110011000000000000000000wwsszz1111550000000011110011000000000000000000wwssRR1111550000000011110011000000000000000000wwssEE1111000000000000110011000000000000000000wwssXX1111000000000000110011000000000000000000wwssoo1111000000000000110011000000000000000000wwssMM1111000000000000110011000000000000000000wwssKK1111000000000000110011000000000000000000wwssll1122115511111133110011000000000000000000ssssll1111000000000000110011000000000000000000wwssll1111000000000000110011000000000000000000wwssmm1111773366881111110011000000000000000000ddddss1177114411880000110011000000000000000000wwssnn1144221166660000110011000000000000000000wwssss1177445511110000110011000000000000000000wwsstt1188556611110000110011000000000000000000aassTT1144991166880000110011000000000000000000wwss441111000000000000110011000000000000000000wwssrr1144112233660000110011000000000000000000wwsshh1122770033220000110011000000000000000000wwssoo1133111133330000110011000000000000000000wwsscc1111772277111144110011000000000000000000ddssSS1122882211880000110011000000000000000000ssssaa1111551144550000110011000000000000000000wwsstt1199118811331100110011000000000000000000wwssxx1111000000000000110011000000000000000000wwssnn1111000000000000110011000000000000000000wwssmm1111771133661111110011000000000000000000mmssJJ1177444411110011110011000000000000000000wwssGG1111551144221100110011000000000000000000wwssss1111000000000000110011000000000000000000wwssLL1111000000000000110011000000000000000000wwssWW1111000000000000110011000000000000000000wwssii1155993333880000110011000000000000000000wwsszz1111000000000000110011000000000000000000wwssgg1111771144661100110011000000000000000000ddssBB1111332277661111110011000000000000000000ssssii1111111111440011110011000000000000000000wwsspp1122115511223311110011000000000000000000ddddTT1111000000000000110011000000000000000000wwssSS1111000000000000110011000000000000000000wwssbb1133111122110000110011000000000000000000wwssMM1111000000000000110011000000000000000000wwssCC1111661122221100110011000000000000000000aassJJ1111000000000000110011000000000000000000wwssJJ1111221144661111110011000000000000000000wwssNN1188555522330000110011000000000000000000wwsspp1199446622440000110011000000000000000000wwssaa1111000000550000110011000000000000000000wwssoo1111000000000000110011000000000000000000wwssww1111000000000000110011000000000000000000wwssDD1111441144881122110011000000000000000000wwssAA1111440011220000110011000000000000000000wwssll1111000000000000110011000000000000000000wwsshh1111000000000000110011000000000000000000wwssPP1188446611330011110011000000000000000000wwss__1144111177770000110011000000000000000000wwssFF1111449922552222110011000000000000000000aassbb1177334411330022110011000000000000000000wwssRR1122664411223366110011000000000000000000ssddJJ1133111100990022110011000000000000000000wwssmm1111000000000000110011000000000000000000wwsskk1122113311113333110011000000000000000000sssscc1122885511114444110011000000000000000000ssssMM1188224411221111110011000000000000000000wwssMM1111771133551100110011000000000000000000ddssMM1144112233880000110011000000000000000000wwssTT1111000000110000110011000000000000000000wwssmm1111228822221100110011000000000000000000wwssNN1111111133550033110011000000000000000000ddssaa1111000000000000110011000000000000000000wwssAA1111000000000000110011000000000000000000wwssxx1166224477110011110011000000000000000000wwssXX1111000000000000110011000000000000000000wwsshh1111000000110000110011000000000000000000wwssss1199117711440011110011000000000000000000wwssww1155223366110000110011000000000000000000wwssJJ1188333322330000110011000000000000000000wwssss1111449933880033110011000000000000000000wwddff1133666622223311110011000000000000000000ssddcc1111000000110000110011000000000000000000wwsspp1111440011110000110011000000000000000000wwssMM1133116633224488110011000000000000000000mmdd111111000000000000110011000000000000000000wwsstt1111000000000000110011000000000000000000wwssbb1111000000000000110011000000000000000000wwssmm1111000000000000110011000000000000000000wwsskk1111772288112288110011000000000000000000ssssQQ1111882233113311110011000000000000000000wwssTT1122444411114488110011000000000000000000nnssEE1122115511228855110011000000000000000000ssssPP1155443322440000110011000000000000000000wwssMM1199115522330022110011000000000000000000wwsscc1177335588111100110011000000000000000000mmssRR1188335511441122110011000000000000000000aassbb1111441111661133110011000000000000000000nnssCC1111441133113311110011000000000000000000ddssDD1111449933661111110011000000000000000000nnssBB1122993311114466110011000000000000000000ssddHH1111557722661155110011000000000000000000nnssgg1111000000110000110011000000000000000000wwssTT1111661122442211110011000000000000000000ddssCC1188885511330022110011000000000000000000wwssRR1144662211110000110011000000000000000000wwssaa1177444477660055110011000000000000000000mmsspp1111445533550044110011000000000000000000wwddAA1166111111330011110011000000000000000000wwddSS1122221111111155110011000000000000000000ssssSS1122112211114433110011000000000000000000ssssBB1111000000000000110011000000000000000000wwssEE1122111111110066110011000000000000000000ssdd661166222211111100110011000000000000000000wwsstt1111000000000000110011000000000000000000wwss
    I am trying to be able to break everything down to a HTML table.

    Earlier I was able to get this,
    Code:
    Array
    (
        [0] => Zerp1234
        [Username] => Zerp1234
        [1] => 1
        [Prestige] => 1
        [2] => 1
        [Level] => 1
        [3] => 0
        [Experience] => 0
        [4] => 0
        [Points] => 0
        [5] => 0
        [Kills] => 0
        [6] => 0
        [Deaths] => 0
        [7] => 0
        [TeamWins] => 0
        [8] => 0
        [TeamLosses] => 0
        [9] => 1
        [Bonus] => 1
        [10] => 0
        [AchievementScore] => 0
        [11] => 1
        [Demented] => 1
        [12] => 0
        [Volatile] => 0
        [13] => 0
        [Undead] => 0
        [14] => 0
        [Scavenger] => 0
        [15] => 0
        [Divinity] => 0
        [16] => 0
        [Withered] => 0
        [17] => 0
        [Killswitch] => 0
        [18] => 0
        [Precise] => 0
        [19] => 0
        [Adept] => 0
        [20] => 0
        [Utility] => 0
        [21] => warrior
        [Class] => warrior
        [22] => showoff
        [Perk] => showoff
    )
    Array
    (
        [0] => yazan123
        [Username] => yazan123
        [1] => 1
        [Prestige] => 1
        [2] => 6
        [Level] => 6
        [3] => 166
        [Experience] => 166
        [4] => 10
        [Points] => 10
        [5] => 13
        [Kills] => 13
        [6] => 17
        [Deaths] => 17
        [7] => 0
        [TeamWins] => 0
        [8] => 1
        [TeamLosses] => 1
        [9] => 1
        [Bonus] => 1
        [10] => 0
        [AchievementScore] => 0
        [11] => 1
        [Demented] => 1
        [12] => 0
        [Volatile] => 0
        [13] => 0
        [Undead] => 0
        [14] => 0
        [Scavenger] => 0
        [15] => 0
        [Divinity] => 0
        [16] => 0
        [Withered] => 0
        [17] => 0
        [Killswitch] => 0
        [18] => 0
        [Precise] => 0
        [19] => 0
        [Adept] => 0
        [20] => 0
        [Utility] => 0
        [21] => warrior
        [Class] => warrior
        [22] => showoff
        [Perk] => showoff
    )
    Then I couldn't get any further to breaking it down into individual items, such as, username, etc

    Thanks
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,183
    Rep Power
    9398
    You have too many loops. $row['Username'] is what you want.
  4. #3
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    More specifically:
    PHP Code:
        while($row mysql_fetch_array($query)) { 
            echo 
    $row['Username'] . "<P />"
        } 
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    189
    Rep Power
    0
    [QUOTE=tjswebdev]I am trying to display information in an array from a MySQL query. I am aware that my queries are depreciated.


    FIRST - the word is deprecated. Not depreciated.

    That said you want to do something like this:

    PHP Code:
    while ($row MySQL_fetch_array($query))
    {
      foreach(
    $row as $k=>$v)
         echo 
    "$k is $v<br>";

    which should give you:

    Username is xxxx
    Prestige is yyyy
    Level is zzzz
    and so on.

IMN logo majestic logo threadwatch logo seochat tools logo