SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Location
    Australia
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    while and mysql_fetch_array

    Hello, I have a table called "characters" with two columns, owner and charname.
    I'm trying to get every row with a person's username in it, and charname in that row too.

    PHP Code:
    $slot_query mysql_query("SELECT charname FROM characters WHERE owner='".$user_row["username"]."'") or die();
    while (
    $slot mysql_fetch_array($slot_queryMYSQL_NUM)) {
    $slot1 $slot[0];
    $slot2 $slot[1];
    $slot3 $slot[2];

    Erm, this will only get 1 charname.
    For example how I want it to work.

    Table: characters
    +--------+----------+
    | owner | charname |
    +--------+----------+
    | user1 | bob |
    +--------+----------+
    | user1 | randy |
    +--------+----------+
    | user1 | tiger |
    +--------+----------+

    slot1 = "bob"
    slot2 = "randy"
    slot3 = "tiger"

    Eh..? Sorry for crappy table -_-''
    Last edited by Ickie; Oct 8, 2006 at 05:46.

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ickie
    I'm trying to get every row with a person's username in it, what charname is in it.
    Can you type that in english please


    It seems that if you want all the usernames you need to take out the where clause in your sql statement. Maybe i have misunderstood
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  3. #3
    An average geek earl-grey's Avatar
    Join Date
    Mar 2005
    Location
    Ukraine
    Posts
    1,403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I understand you correctly, you want owner field to be present in the result set as well:
    Code:
    SELECT charname, owner FROM characters WHERE owner='".$user_row["username"]."'"
    You can get the array containing all rows with this code:
    PHP Code:
    <?php
    $slots 
    = array();
    while (
    $slot mysql_fetch_array($slot_queryMYSQL_NUM)) { 
    $slots[] = $slot
    }
    $slot1 $slots[0]['charname'];
    $slot2 $slots[1]['charname'];
    $slot3 $slots[2]['charname'];
    ?>

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Location
    Australia
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $x 0;
    while (
    $row mysql_fetch_array($slot_query)) {
    $slot[$x] = $row['charname'];
    $x++;

    This is what I wanted. Sorry for the trouble guys.


Bookmarks

Posting Permissions

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