Results 1 to 3 of 3

Thread: PHP/Array question

  1. #1
    on way to buy Apt Pupil
    Join Date
    Feb 2005
    Posts
    192
    Thanks
    1
    Thanked
    0 times in 0 posts

    PHP/Array question

    Hello
    I have this portion of code:
    PHP Code:
    $ar_query "SELECT id,name FROM categories";

    $ar_result mysql_query($ar_query) or die(mysql_error());
    $ar_row mysql_fetch_array($ar_result) or die(mysql_error());


    while(
    $ar_row mysql_fetch_array($ar_result)){

    echo 
    "on row:" $ar_row['id'] . "<br>";

    $cat_names[$ar_row['id']] = $ar_row['name'];



    So it should start at id = 1, which should make $ar_row['name'] start at 1, giving the value of "General" (from the db), but it only starts at the 2nd one (ie the 2nd row from my db)
    Any ideas?

  2. #2
    Bigger than Jesus Norky's Avatar
    Join Date
    Feb 2005
    Posts
    1,579
    Thanks
    1
    Thanked
    8 times in 8 posts
    Try this:

    PHP Code:
    $ar_query "SELECT id,name FROM categories";

    $ar_result mysql_query($ar_query) or die(mysql_error());
    if(
    mysql_num_rows($ar_result)<1)
    die(
    'No results returned');

    while(
    $ar_row mysql_fetch_array($ar_result)){

    echo 
    "on row:" $ar_row['id'] . "<br>";

    $cat_names[$ar_row['id']] = $ar_row['name'];



    Saves reassigning the array, not sure if it will fix your problem though

  3. #3
    on way to buy Apt Pupil
    Join Date
    Feb 2005
    Posts
    192
    Thanks
    1
    Thanked
    0 times in 0 posts
    Thanks it works now

    Noticed another error later on in the code as well that was stopping it from displaying certain id's which i hadn't noticed(but not to do with id=1)

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Personal Question game.....
    By Kitty in forum General Discussion
    Replies: 394
    Last Post: 29-01-2006, 11:50 AM
  2. Replies: 6
    Last Post: 21-10-2005, 08:50 AM
  3. Quick Question: PSU's with 1x120mm fan question
    By philyau in forum PC Hardware and Components
    Replies: 10
    Last Post: 05-09-2005, 02:30 PM
  4. The 78th Annual Hexus Quiz!
    By Stewart in forum General Discussion
    Replies: 19
    Last Post: 23-01-2005, 02:05 PM
  5. What is Question Time
    By Saracen in forum Question Time
    Replies: 0
    Last Post: 12-08-2003, 05:50 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
  •