www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] stopping an array from clearing data after function call

  1. #1
    Join Date
    Jan 2009
    Location
    Ixonia, WI
    Posts
    56

    resolved [RESOLVED] stopping an array from clearing data after function call

    i'm getting data from a table and I'm running it through a function to extract all the rows from each field. Here is the function:
    Code:
    function mysql_fetch_all($result, $number) {
       while($row=mysql_fetch_array($result)) {
         echo $row[$number]."<br>";
    	  $return[] = $row;
       }
       return $return;
    }
    I'm calling this function from here:

    Code:
    function showTable($table_name, $primary_key, $index, $secondary_column, $div_header, $div_header2, $divID, $divID2){
    	$show_all = mysql_query("SELECT * FROM $table_name WHERE $primary_key < 100");
    	echo "<div id='$divID'><h4>".$div_header."</h4><p>";
    	mysql_fetch_all($show_all, 1);
    	echo "</p></div>";
    	echo "<div id='$divID2'><h4>". $div_header2."</h4><p>";
    //	$show_all = mysql_query("SELECT * FROM $table_name WHERE $primary_key < 100");
    	mysql_fetch_all($show_all, 2);
    	echo "</p></div>";
    }
    I think when i make the first call it is erasing the contents of the array from my $show_all SELECT statement. I have to uncomment the second $show_all in order for the function mysql_fetch_all to return the #2 data.

    I don't want to have to make another query to call the function again (unless there isn't another way). Thanks in advance...

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,241
    It's not erasing. When you run a mysql_fetch_*() on a query result, each call moves the row pointer to the next row of the result. If you want to run through it again then you need to do a mysql_data_seek() to move the row pointer back to row 0 (zero). So you probably want to add the data seek call to the start of your fetch all function.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jan 2009
    Location
    Ixonia, WI
    Posts
    56
    perfect! thanks again NogDog! you d'man!

Thread Information

Users Browsing this Thread

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

Posting Permissions

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



Recent Articles