SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot thetzfreak's Avatar
    Join Date
    Aug 2004
    Location
    United States
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is it possible to use your own numbers in arrays?

    Hey,

    Is it possible to use your own numbers in arrays instead of the standard ones? Instead of starting from 0 and going up, can I set my own?

    Reason is, I have category numbers in my database (which don't have any particular order) and each category number has a corresponding category name. So, if the first category number 54 is "art", the first item in the array would be $cat[54] = "art".

    I'm doing something like this:

    PHP Code:
    $result1 mysql_query("SELECT category,id FROM categories ORDER BY category ASC");
    while (
    $row1 mysql_fetch_array($result1)) {
        
    $cats[] = array($row1['id'] => $row1['category']);

    Can I do this? All I'm trying to do is get variables with their IDs and category names. Perhaps there's an easier way to do this, I just can't think right now =(

    Thanks.

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    while ($row1 = mysql_fetch_array($result1)) {
         $cats[$row1['id']] = $row1['category'];
    }

  3. #3
    SitePoint Zealot thetzfreak's Avatar
    Join Date
    Aug 2004
    Location
    United States
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    D'oh. Thanks a lot.


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
  •