ArizonaJohn Posted June 16, 2009 Share Posted June 16, 2009 Hello, The code below works correctly. It creates a nice little array called $table_list[]. This array varies in size based on $entry. How can I echo/print all of the values in $table_list[] regardless of what $entry is? Thanks in advance, John while(list($table)= mysql_fetch_row($result)) { $sqlA = "SELECT COUNT(*) FROM `$table` WHERE `site` LIKE '$entry'"; $resA = mysql_query($sqlA) or die("$sqlA:".mysql_error()); list($isThere) = mysql_fetch_row($resA); if ($isThere) { $table_list[] = $table; } } Quote Link to comment https://forums.phpfreaks.com/topic/162342-solved-printing-out-an-array-that-can-vary-in-size/ Share on other sites More sharing options...
Dathremar Posted June 16, 2009 Share Posted June 16, 2009 This query "SELECT COUNT(*) FROM `$table` WHERE `site` LIKE '$entry'" will always have only one record which will contain the number of matches. Quote Link to comment https://forums.phpfreaks.com/topic/162342-solved-printing-out-an-array-that-can-vary-in-size/#findComment-856895 Share on other sites More sharing options...
ArizonaJohn Posted June 16, 2009 Author Share Posted June 16, 2009 I'm running it as a loop, so $table_list[] ends up having several entries. I tried echoing $table_list[1] $table_list[2] for entries that I know have more than one table name, and it works. What I want to do is print out all of the table names in the array, regardless of how many there are. Quote Link to comment https://forums.phpfreaks.com/topic/162342-solved-printing-out-an-array-that-can-vary-in-size/#findComment-856897 Share on other sites More sharing options...
Zane Posted June 16, 2009 Share Posted June 16, 2009 echo ""; print_r($table_list); echo ""; Quote Link to comment https://forums.phpfreaks.com/topic/162342-solved-printing-out-an-array-that-can-vary-in-size/#findComment-856903 Share on other sites More sharing options...
Dathremar Posted June 16, 2009 Share Posted June 16, 2009 There is a print_r function in php, but I doubt You will want that kind of output But You can always do something like: for ($i=0; $i < count($table_list); $i++) { echo $table_list[$i]; } Quote Link to comment https://forums.phpfreaks.com/topic/162342-solved-printing-out-an-array-that-can-vary-in-size/#findComment-856904 Share on other sites More sharing options...
Philip Posted June 16, 2009 Share Posted June 16, 2009 There is a print_r function in php, but I doubt You will want that kind of output But You can always do something like: for ($i=0; $i < count($table_list); $i++) { echo $table_list[$i]; } Or, using foreach (which was built for arrays): foreach($array as $key => $value) { echo $value,'<br>'; } Quote Link to comment https://forums.phpfreaks.com/topic/162342-solved-printing-out-an-array-that-can-vary-in-size/#findComment-856906 Share on other sites More sharing options...
FWDrew Posted June 16, 2009 Share Posted June 16, 2009 There is a print_r function in php, but I doubt You will want that kind of output But You can always do something like: for ($i=0; $i < count($table_list); $i++) { echo $table_list[$i]; } But, print_r is extremely useful for debugging and testing purposes Quote Link to comment https://forums.phpfreaks.com/topic/162342-solved-printing-out-an-array-that-can-vary-in-size/#findComment-856954 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.