Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    50
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question want to echo multiple rows

    I am using while loop to echo all rows from a table, e.g.,
    while($row=mysql_fetch_row($result)) {echo"....";} and it is working fine but i want another way to echo all rows without using loop so that i can assign a variable to every resulting row. Is there any other method to do so??

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    but i want another way to echo all rows without using loop so that i can assign a variable to every resulting row.
    Sorry, your requirement is not clear.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Sep 2011
    Posts
    50
    Thanks
    4
    Thanked 0 Times in 0 Posts
    This is my code to retrieve all rows which are having quantity=8

    $sql="SELECT items FROM datatable WHERE quantity='8'";
    $query=mysql_query($sql);
    $row=mysql_fetch_row($query);
    echo"$row[0]";

    But this code retrieve only the first row. How can i retrieve all rows without using loop?

  • #4
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,963
    Thanks
    120
    Thanked 76 Times in 76 Posts
    I guess all rows are retriewed at once from db. So you have all at client side at once, if that is your concern ? You are looping on client side dataset.
    But I dont know PHP, 'fetch' looks fishy to me, like it realy fetches row by row from db?
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    but i want another way to echo all rows without using loop so that i can assign a variable to every resulting row.
    I still understand why can't you use a loop here
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #6
    New Coder
    Join Date
    Sep 2011
    Posts
    50
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I dont want to use loop because i think that there should be an inbuilt function in mysql to do this. I think that mysql_fetch_array() can retrieve all rows, but when i use this function, only the word "Array" is echoed, instead of all rows. If mysql_fetch_array doesn't retrieve all rows without using loop, then please tell me the other way.

  • #7
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try adding this code

    <?php
    $qry = "SELECT * FROM exp_member_data";
    $res = mysql_query($mem_qry);

    function mysql_fetch_all($res) {
    while($row=mysql_fetch_array($res)) {
    $return[] = $row;
    }
    return $return;
    }

    function create_table($dataArr) {
    echo "<tr>";
    for($j = 0; $j < count($dataArr); $j++) {
    echo "<td>".$dataArr[$j]."</td>";
    }
    echo "</tr>";
    }

    $all = mysql_fetch_all($res);

    echo "<table class='data_table'>";

    for($i = 0; $i < count($all); $i++) {
    create_table($all[$i]);
    }

    echo "</table>";

    ?>
    Last edited by WA; 02-27-2012 at 10:06 PM.

  • #8
    New Coder
    Join Date
    Sep 2011
    Posts
    50
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Is mysql_data_seek() or mysql_result() useful to retrieve all rows?


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •