SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How can I simplify <?php echo htmlspecialchars(implode(', ', $areas)); ?>???

    With my old script, I could display data like this:

    PHP Code:
    <td>{$row["Area"]}</td
    But I couldn't make it perform one very important function. I now have a new script that does what I want, but the display is much more complex.

    I'd like to replace these...

    PHP Code:
    <?php echo htmlspecialchars(implode(', '$areas)); ?>
    <?php 
    echo htmlspecialchars($class); ?>
    with something simpler. It would be great if I could just paste in $Areas and $Class wherever I want to display those two items. At the moment, I don't even have a clue about displaying other variables.

    For example, I'd like to display this...

    PHP Code:
    <?php echo htmlspecialchars($class); ?> ($row['ClassCommon'])
    where $class is the scientific name and ClassCommon is the common name. So the output would look like this:

    Coleoptera (beetles)

    Anyway, can someone show me how to tame this script? Thanks.

    PHP Code:
    $res = mysql_query("SELECT DISTINCT(`Order`), Area, Class, OrderCommon FROM symbols 
    WHERE Class = '$myname' ORDER BY `Order`");

    $groups = array();
    while ($row = mysql_fetch_assoc($res)) {
        $groups[$row['Order']][] = $row['Area'];
    }
    ?>
    <table>
    <tr><th>1</th><th>2</th></tr>


      <?php foreach ($groups as $class => $areas) { ?>
        <tr>
          <td class = "tdname" style="background-color: <?php $color_sets[$c][0?>">
            <?php echo htmlspecialchars(implode(', '$areas)); ?>
          </td>
          <td class = "tdsymbol" style="background-color: <?php $color_sets[$c][1?>">
            <?php echo htmlspecialchars($class); ?>
          </td>
        </tr>
      <?php ?>

    </table>

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll take a stab at part of this.

    Quote Originally Posted by geosite

    For example, I'd like to display this...

    PHP Code:
    <?php echo htmlspecialchars($class); ?> ($row['ClassCommon'])
    where $class is the scientific name and ClassCommon is the common name. So the output would look like this:

    Coleoptera (beetles)

    To get that, try this:

    PHP Code:
    <?php echo htmlspecialchars($class) . ' (' $row['ClassCommon'] . ')'?>
    Last edited by k0ng; May 9, 2005 at 12:03. Reason: not sure about my other point, so I nuked it


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •