SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Guru D-flyer's Avatar
    Join Date
    Jan 2001
    Location
    Near a computer
    Posts
    782
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    It works fine, but

    there must be a better way. I am a php-newbie:
    [php]
    $numOfAvatars = mysql_num_rows($result);

    echo "$numOfAvatars";
    $i=0;
    IF($numOfAvatars==0){
    echo "&status=" .urlencode("No others have been found");
    }ELSEIF($numOfAvatars>0){
    echo "&status=$numOfAvatars others have been found";
    WHILE($i<$numOfAvatars) {
    $userName=mysql_result($result,$i,"userName");
    // display avatar names
    echo "&userName$i=$userName";
    $i++;
    }
    }

    [/code]

    All i want is to get a output in this form:
    &userName0=a&userName1=b&userName2=c&userName3=d etc.

    I don't like my use of $userName=mysql_result($result,$i,"userName");

    Any suggetions?

  2. #2
    epsilon transition cupid's Avatar
    Join Date
    Aug 2001
    Location
    Kent, Ohio
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mysql_fetch_* are functions designed for multiple fetches like what you're doing.

    PHP Code:

    /* top code snipped */
    elseif ($numOfAvatars>0) {
            echo 
    "&status=$numOfAvatars others have been found";

            while (
    $user mysql_fetch_array($result))
                    echo 
    "&userName$i=$user[userName]";


  3. #3
    SitePoint Guru D-flyer's Avatar
    Join Date
    Jan 2001
    Location
    Near a computer
    Posts
    782
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thx cupid,

    going to check the mysql_fetch_array function at mysql.org

    your code works like a charm

    //Grtz

  4. #4
    epsilon transition cupid's Avatar
    Join Date
    Aug 2001
    Location
    Kent, Ohio
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great! By the way.. mysql_fetch_array is a PHP function. You'd get better documentation on php.net


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
  •