#1
  1. King of da Wackos
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2005
    Location
    Planet Zeekois
    Posts
    92
    Rep Power
    0

    Question Post link based on column name, with space between words


    Original code.
    Code:
    $row = mysql_fetch_assoc ($result);
    echo "<TABLE border=1>\n";
    echo "<TR>\n";
    foreach ($row as $heading=>$column)
    {
        echo "<TD><b><a href={$_SERVER['PHP_SELF']}?order=$heading>$heading</a></b></TD>";
    }
    echo "</TR>\n";
    How do I make the code below show the column names with a space between the words?
    Code:
    $row = mysql_fetch_assoc ($result);
    echo "<TABLE border=1>\n";
    echo "<TR>\n";
    foreach ($row as $heading=>$column)
    if($column == 'ColumnOne')
    {
        echo "<TD><b><a href={$_SERVER['PHP_SELF']}?order=$heading>Column One</a></b></TD>";
    }
    if($column == 'AnotherColumn')
    {
        echo "<TD><b><a href={$_SERVER['PHP_SELF']}?order=$heading>Another Column</a></b></TD>";
    }
    else
     {
        echo "<TD><b><a href={$_SERVER['PHP_SELF']}?order=$heading>$heading</a></b></TD>";
    }
    echo "</TR>\n";
    Just a coding n00bie, and is most likely a SPAMMER, and a traitor to da cause!!!

    Um, can some one give me some red??!! I got '1 points total' so I need just one negative rep to get back to being most likely a SPAMMER, and a traitor to da cause!!!

  2. #2
  3. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
    Alias the columns in your query.
    Code:
    SELECT ColumnOne AS `Column One`, AnotherColumn AS `Another Column`...
    and please, for the love of HTML,
    PHP Code:
    echo "<TH><a href='" htmlentities($_SERVER['PHP_SELF']) . "?order=" urlencode($heading) . "'>$heading</a></TH>"
    There's actually another problem but hopefully you'll find it soon.

IMN logo majestic logo threadwatch logo seochat tools logo