amites Posted November 10, 2007 Share Posted November 10, 2007 Well I'm working on my first serious PHP mySQL project in a while and running into a road block $sql = "SELECT * FROM venue_seating WHERE venue_id = '" .$venue['venue_id']. "' AND section = '" .$venue_row['section']. "' ORDER BY row ASC"; $res = mysql_query($sql) or die(mysql_error()); var_dump($res); while ($rec = mysql_fetch_assoc($res)) { the var_dump says there are 11 resources recovered from the query, but when I try to print them out after the while statement it leaves me blank... what am I missing, I know it's obvious, thinking 13 hours might be my limit for the day... Quote Link to comment Share on other sites More sharing options...
toplay Posted November 10, 2007 Share Posted November 10, 2007 You don't dump $res which is the resource to the results. You want to access the data through the $rec variable within the "while" loop. i.e. echo $rec['column_name']; Quote Link to comment Share on other sites More sharing options...
amites Posted November 10, 2007 Author Share Posted November 10, 2007 I added the var_dump after it wasn't providing any results, I've gone through and checked before and after the while statement, and the only thing that stays true is that before the while statement there are results in the array and none after it, I based the query on results from a previous query not sure what's off, only that it's something obvious, for a little more detail I'm throwing in more of the surrounding code... $sql = "SELECT * FROM venue_seating WHERE venue_id = '" .$venue['venue_id']. "' AND section = '" .$venue_row['section']. "' ORDER BY row ASC"; $res = mysql_query($sql) or die(mysql_error()); // var_dump($res); while ($rec = mysql_fetch_assoc($res)) { // print $rec; $venue_seat[] = $rec; print_r ($venue_seat); // var_dump ($rec); // var_dump ($venue_seat); everything after the while statement comes up blank, before it has 11 resources available... I appreciate the help with something I know is simple Quote Link to comment Share on other sites More sharing options...
toplay Posted November 10, 2007 Share Posted November 10, 2007 Again, forget about dumping $res and after the while loop because the data has already been read (within the while loop) so there's nothing to dump per say. Each of your post never show the complete code in the while loop or at least you don't show where the ending right curly brace is ("}"). Do you really have a column simply called "row"? What are you trying to do exactly? Are you trying to save off all the row results? because that's what it looks like you're doing with: $venue_seat[] = $rec; <?php // Open and select DB up here $sql = "SELECT * FROM `venue_seating` WHERE `venue_id` = '" .$venue['venue_id']. "' AND `section` = '" .$venue_row['section']. "' ORDER BY `row` ASC"; $res = mysql_query($sql) or die(mysql_error()); $venue_seat = array(); while ($rec = mysql_fetch_assoc($res)) { print_r($rec); // Would print one row of data - each column is an associated array index with it's value $venue_seat[] = $rec; // This saves the array $rec into another array called $venue_seat to save every row } // end of while loop print_r($venue_seat); // would print an array of associated row arrays ?> Look at manual page for other code example: http://us2.php.net/manual/en/function.mysql-query.php Quote Link to comment Share on other sites More sharing options...
amites Posted November 11, 2007 Author Share Posted November 11, 2007 thank you toplay, I had to run around in a circle for a few minutes putting a nice long thought out question together and came to my own answer, $venue_row[] was being set by a previous query and resulted in a nested array which I didn't see until I var_dumped each variable at each step, now time to refresh myself on pulling value from a nested array and I'm on to the next part of this project, tracking tickets to events in these places... 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.