CodeIgniter Forums

Full Version: Syntax Error with URL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello

I am just having a problem with the URLS in my For loop. I am trying to get the Table ID when a Link is clicked. Here is the code:


Code:
<?php
    $men = 'men';
    $women = 'women';
    foreach($distances as $distance) {
        echo "<div class='row'>";
        echo "<div class='col'>";
        echo "<table class='table' cellspacing='10'  cellpadding='10'>";
        echo "<tr>";
        echo "<th colspan='2'><h1>" . $distance . "</h1></th>";
        echo "</tr>";
        echo "<tr><th style='font-size: 20px;'>Men</th><th style='font-size: 20px;'>Women</th></tr>";
        for ($i=0; $i<=count($tables['men']); $i++) {
            echo "<tr>";
            if (substr($tables['men'][$i], -4) == $distance) {
                echo '<td><a href="' . site_url("select/gettable/$tables[$men][$i]")  . '" class="link-class">' . $tables['men'][$i] . '</a></td>';
                echo '<td><a href="' . site_url("select/gettable/$tables[$women][$i]")  . '" class="link-class">' . $tables['women'][$i] . '</a></td>';
            }
            echo "</tr>";
        }
        echo "</table>";
        echo "</div>";
        echo "</div>";
    }
?>

The problem is with the following line. It has something to do with passing the array $tables['men'][$i]. I am getting the error of Array to string conversion.

Code:
echo '<td><a href="' . site_url("select/gettable/$tables['men'][$i]")  . '" class="link-class">' . $tables['men'][$i] . '</a></td>';

When I had it as just:


Code:
echo '<td><a href="' . site_url("select/gettable/$tables")  . '" class="link-class">' . $tables['men'][$i] . '</a></td>';

Everything worked perfectly, so I am not sure if I am simply formatting the URL properly, or if you cannot pass arrays to the URL.
Hi, it should be like this:

PHP Code:
echo '<td><a href="' site_url("select/gettable/" $tables['men'][$i])  '" class="link-class">' $tables['men'][$i] . '</a></td>'

If it's not working. $tables['men'][$i] contains an array and not a string.