Jump to content

[SOLVED] Printing out an Array that can vary in size


ArizonaJohn

Recommended Posts

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;
  }
}

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.

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>';
}

 

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 ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.