Need help to get more than row at the same time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zarwadi
    New Member
    • Jun 2007
    • 34

    Need help to get more than row at the same time

    Hi can anyone help me, I need to fetch more than 1 row at the same time. I've used print_r(mysql_f etch_array($res ult)); but I only get 1 row is there away of of getting more then 1 row.
    kind regards
    Zawadi
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #2
    Originally posted by Zarwadi
    Hi can anyone help me, I need to fetch more than 1 row at the same time. I've used print_r(mysql_f etch_array($res ult)); but I only get 1 row is there away of of getting more then 1 row.
    kind regards
    Zawadi
    Hi,

    Try something like this:
    [CODE=php]
    while ($row = mysql_fetch_arr ay($result, MYSQL_BOTH))
    {
    if ($row)
    {
    echo $row;
    }
    }
    [/CODE]

    This should print each row in the result of the query. If this only ever returns 1 row of data then perhaps that's all that was returned? Check the SQL

    Cheers
    nathj

    Comment

    • Zarwadi
      New Member
      • Jun 2007
      • 34

      #3
      Originally posted by nathj
      Hi,

      Try something like this:
      [CODE=php]
      while ($row = mysql_fetch_arr ay($result, MYSQL_BOTH))
      {
      if ($row)
      {
      echo $row;
      }
      }
      [/CODE]

      This should print each row in the result of the query. If this only ever returns 1 row of data then perhaps that's all that was returned? Check the SQL

      Cheers
      nathj
      Thanks this really did help, but the output is Array Array Array. How do i get the data from the arrays.
      Thanks for your reply
      zar

      Comment

      • mwasif
        Recognized Expert Contributor
        • Jul 2006
        • 802

        #4
        MYSQL_BOTH is the default value of mysql_fetch_arr ay(). Try the below code

        [PHP]while ($row = mysql_fetch_arr ay($result))
        {
        echo $row["your_column_na me_here"];
        }[/PHP]

        Comment

        • Zarwadi
          New Member
          • Jun 2007
          • 34

          #5
          Thanks but I must be doing something wrong all I'm getting is the column data in a string and what i need is all the rows i'm calling set in an array. I know i have 3 rows of data and I need them to look like this, but all 3 rows.

          Array
          (
          [0] => 1
          [id] => 1
          [1] => test
          [name] => test
          [2] => 86
          [subtotal] => 86
          [3] => t541
          [identnum] => t541
          [4] => 1
          [itemqut] => 1
          [5] => Vinyl camera case
          [itemproduct] => Vinyl camera case
          [6] => None
          [itemsize] => None
          [7] => 57.00
          [itemprice] => 57.00
          )
          but I'm only getting 1 row,

          if you can help I would be very greatful
          kind regards
          Zar

          Comment

          • mwasif
            Recognized Expert Contributor
            • Jul 2006
            • 802

            #6
            Please post your code.

            Comment

            • Zarwadi
              New Member
              • Jun 2007
              • 34

              #7
              this line tells database which rows to look at the one with same username $glog is a var of the user name sent by the user.
              $query = "SELECT * FROM theOrder WHERE name ='$glog'";

              this is the query
              $result = mysql_query($qu ery);

              the number of rows from the query
              $numR = mysql_num_rows( $result);

              the array data this is good but it only gives me the 1st row, and like i said there are 3 row using the same user name and i need all 3 rows set out in a array
              print_r(mysql_f etch_array($res ult));

              Could you tell what I have done wrong

              kind regards
              Zar

              Comment

              • mwasif
                Recognized Expert Contributor
                • Jul 2006
                • 802

                #8
                Did you use while() as nathj suggested? Look at the below code.
                [PHP]$query = "SELECT * FROM theOrder WHERE name ='$glog'";

                $result = mysql_query($qu ery);
                while($row = mysql_fetch_arr ay($result))
                {
                print_r($row);
                }[/PHP]

                Comment

                • Zarwadi
                  New Member
                  • Jun 2007
                  • 34

                  #9
                  Thank you, thank you thank, I must have done something stupid your my savior

                  Zar

                  Comment

                  • nathj
                    Recognized Expert Contributor
                    • May 2007
                    • 937

                    #10
                    One final point, if I may. Check out the article on building a data abstraction layer. It'll really help with this sort of stuff and it will properly modularise all your code for you making it easier to maintain and re-use.

                    Cheers
                    nathj
                    Last edited by nathj; Jul 24 '07, 06:03 AM. Reason: removing quote

                    Comment

                    Working...