Missing element in array?!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Akhenaten

    Missing element in array?!

    I have the following query I run to pull some data from the db. The
    sql (when run on the db) returns 2 elements. However, if I var dump my
    variable ($aidlook) then the first element in the array does not show
    up.

    $getaid = mysql_query("SE LECT a_uid FROM `answers` WHERE `qid` =
    $qid", $db);
    $aidlook = mysql_fetch_arr ay($getaid,MYSQ L_NUM);

    Doing a var dump returns: array(1) { [0]= string(1) "4" }

    I should be getting 2 elements (4 and 5).

    I am totally baffled. code as follows:

    *************** ******
    if (!is_array($aid look)) $aidlook = array($aidlook) ; // Check for the
    existence of the array in case of null returns

    if (!in_array($use rid,$aidlook)) // Look for our element which in
    this case is "5"
    {
    if ($qstatus === 1) // Do a status check
    {
    }

    answer_box($qid ,$answ); // additional function being run

    } else
    {
    echo "Your Text Here";

    }
    }


    ../JLK

  • Gordon Burditt

    #2
    Re: Missing element in array?!

    >I have the following query I run to pull some data from the db. The
    >sql (when run on the db) returns 2 elements. However, if I var dump my
    >variable ($aidlook) then the first element in the array does not show
    >up.
    >
    >$getaid = mysql_query("SE LECT a_uid FROM `answers` WHERE `qid` =
    >$qid", $db);
    >$aidlook = mysql_fetch_arr ay($getaid,MYSQ L_NUM);
    >
    >Doing a var dump returns: array(1) { [0]= string(1) "4" }
    >
    >I should be getting 2 elements (4 and 5).
    mysql_fetch_arr ay returns the results from ONE ROW. Since you are
    only selecting one column in your query, you should have only one
    element in the array. If you want the results from more than one
    row, loop calling mysql_fetch_arr ay. Note that if you try doing
    this and then merging the arrays, you're going to merge a whole
    lot of arrays with a "0" index and likely you will end up with an
    array with a single "0" index.

    >I am totally baffled. code as follows:
    >
    >************** *******
    >if (!is_array($aid look)) $aidlook = array($aidlook) ; // Check for the
    >existence of the array in case of null returns
    >
    > if (!in_array($use rid,$aidlook)) // Look for our element which in
    >this case is "5"
    > {
    > if ($qstatus === 1) // Do a status check
    > {
    > }
    >
    >answer_box($qi d,$answ); // additional function being run
    >
    > } else
    > {
    >echo "Your Text Here";
    >
    >}
    >}
    >
    >
    >./JLK
    >

    Comment

    • Akhenaten

      #3
      Re: Missing element in array?!

      mysql_fetch_arr ay returns the results from ONE ROW. Since you are
      only selecting one column in your query, you should have only one
      element in the array. If you want the results from more than one
      row, loop calling mysql_fetch_arr ay. Note that if you try doing
      this and then merging the arrays, you're going to merge a whole
      lot of arrays with a "0" index and likely you will end up with an
      array with a single "0" index.
      >
      That I did not know..... Thank you.

      ../JLK

      Comment

      Working...