severndigital Posted November 4, 2008 Share Posted November 4, 2008 ok .. i am working on a class function that will take the sql statement and loop through it to return an array. i'm stuck in the middle .. if anyone can help, it would be great. here's what i have class database { public function returnArray($sql) { $pull = mysql_query($sql) or die ('Return Array Failed: ' . mysql_error()); $returnArray = array(); //this is where i get stuck while($r = mysql_fetch_array($pull){ $itemArray = array(); //how do i put the $r items into the array $itemArray ??? $returnArray[] = $itemArray; } return $returnArray; } i tried using this while($r = mysql_fetch_array($pull){ $itemArray = array(); for($i = 0;$i <count($r); $i++){ $itemArray[] = $r[$i]; } $returnArray[] = $itemArray; } but i get tons of invaild resource id errors can anyone help?? Thanks, -C Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 4, 2008 Share Posted November 4, 2008 while($r = mysql_fetch_array($pull){ $returnArray[] = $r; } Quote Link to comment Share on other sites More sharing options...
severndigital Posted November 4, 2008 Author Share Posted November 4, 2008 ok that kind of worked ..but it's return twice as much information .. what can i do to ONLY return the array with either a number or the fieldname here is what gets returned: Array ( [0] => Array ( [0] => 1 [elementId] => 1 [1] => 1 [userId] => 1 [2] => 1 [designId] => 1 [3] => text [elementType] => text [4] => 0 [xCord] => 0 [5] => 0 [yCord] => 0 [6] => New Text [elementValue] => New Text ) [1] => Array ( [0] => 2 [elementId] => 2 [1] => 1 [userId] => 1 [2] => 1 [designId] => 1 [3] => text [elementType] => text [4] => 0 [xCord] => 0 [5] => 0 [yCord] => 0 [6] => New Text [elementValue] => New Text ) ) i cannot preform a for loop correctly on the information because it returns twice as many when i do the count() thanks, -C Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 4, 2008 Share Posted November 4, 2008 while($r = mysql_fetch_array($pull, MYSQL_NUM){ $returnArray[] = $r; } Quote Link to comment Share on other sites More sharing options...
severndigital Posted November 4, 2008 Author Share Posted November 4, 2008 Thanks .. worked perfect. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.