• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax Error with URL


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:

    $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.

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:

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.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.