Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.