Hello all,

I am having an issue.
The issue being is that i have a page connecting to a database and displaying it in tables. The problem is, is that I have one column in my page where I want to do this:

<td bgcolor="#817679"><center><? echo $rows['Airport']; ?><? echo $rows['Type']; ?></center></td>

Display both rows in one cell with a space, is there an Easier Way to do this??

The other Problem I need help with is, for the Type it displays as :: Clr, Twr, Gnd, Del, Apr, and Dep.

Is there a way to find

<td bgcolor="#817679"><center><? echo $rows['Type']; ?></center></td>

the clr etc... and Replace with another Word such as Clr = Clearance? ? ?

Could someone please help? Thanks in advance. :)

Dani AI

Generated

described two needs: show Airport and Type in a single table cell, and replace short Type codes (like "Clr", "Twr") with full labels. 's mapping idea is correct; the following expands on it with robustness (handles leading punctuation, mixed case, missing values) and safe output.

A compact, safer PHP pattern (run the mapping once, normalize the raw value, provide a default, and escape output):

// normalize a raw value that might be like ":: Clr"
$raw = $rows['Type'] ?? '';
$code = strtoupper(preg_replace('/[^A-Za-z]/', '', $raw)); // keeps letters only

// mapping kept outside any row loop for efficiency
$types = [
  'CLR' => 'Clearance',
  'TWR' => 'Tower',
  'GND' => 'Ground',
  'DEL' => 'Delivery',
  'APR' => 'Approach',
  'DEP' => 'Departure',
];

$label = $types[$code] ?? 'Unknown';
$airport = htmlspecialchars($rows['Airport'] ?? '', ENT_QUOTES, 'UTF-8');

echo $airport . ' ' . htmlspecialchars($label, ENT_QUOTES, 'UTF-8');

Notes and troubleshooting:

  • If Type strings really include prefixes like ":: ", strip them first (the regex above does that). Use var_dump($rows['Type']) to inspect unexpected formats.
  • For many or editable labels, use a lookup table in the database and join on it (better for localization and maintenance) or map in the SQL CASE clause.
  • Keep the map outside the loop to avoid re-creating it for every row.
  • Always escape DB output (htmlspecialchars) to prevent XSS, and use prepared statements when querying the DB.

Recommended Answers

All 2 Replies

<?php
//bla bla bla
$airtype = array("clr" => "clearance","twr" => "tower", "gnd" => "Ground", "dep" => "departure"); //etc
echo $rows['airport']." ".$airtype[$rows['type']];
?>

pulls the value from another array, perhaps

if it works, please click solved
I get an attaboy

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.