How do i start this sorting?

OK here’s the deal.
We have data in our database (a database of cell sites) with one row of data per sector. Our vendor needs this data with one row per site, with the sectorized data as additional columns. I have been charged with creating a macro, or web application that will take care of this.
For clarification, here’s a small representation of the dataset, and an example of the final product:

#######################
OUR DATA
#######################
Site Name | Antenna | Azimuth | Status
SITE1_X     | Antenna1| 30deg    |OA
SITE1_Y     | Antenna2| 90deg    |OA
SITE1_Z     | Antenna3| 180deg  |OA
SITE2_O     | Omni      | 0deg      |OA
#######################

This is how the data needs to be sorted:

#######################
Site Name | Antenna (Sector 1) | Antenna (Sector 2) | Antenna (Sector 3) | Azimuth (Sector 1)| Azimuth (Sector 2) | Azimuth (Sector 3) | Status
SITE1       | Antenna1                |Antenna2               | Antenna3               | 30deg        | 90deg                   | 180deg| OA
Site2         | Omni                      |                             |                            |0deg                    |OA
#######################

I am not sure how to go about getting the data in this format. Another thing to consider is that not all sites have 3 sectors, some have 1 (omni), some have only 2 sectors, and the rest have 3 sectors. The omni site names end with _O, the sectorized sites end with _X, _Y, or _Z. I would like to use php, not an excel macro, because of portability (no odbc drivers to install or configure on each users machine), and speed.
Do any of you have any suggestions on how I should begin building this?
I have already created the query that gets the data from our db, but am a little confused as to where to go now.
Thanks in advance.

Here is how I was thinking about tackling this…I just don’t know exactly how to write the “if” statement. I was looking into the string functions on the php site…

<table border="0" cellspacing="0" id="table" class="ruler">
  <tr>
    <th scope="column">Centennial Plan</th>
    <th scope="column">Technology</th>
    <th scope="column">Switch</th>
    <th scope="column">Site ID</th>
    <th scope="column">Cell Site Name</th>
    <th scope="column">Dec Long</th>
    <th scope="column">Dec Lat</th>
    <th scope="column">Street</th>
    <th scope="column">City</th>
    <th scope="column">State</th>
    <th scope="column">Zip</th>
    <th scope="column">County/Parish</th>
    <th scope="column">CR AGL (ft)</th>
    <th scope="column">Antenna Model Sector 1</th>
    <th scope="column">Antenna Model Sector 2 </th>
    <th scope="column">Antenna Model Sector 3 </th>
    <th scope="column">Azimuth Sector 1 (deg) </th>
    <th scope="column">Azimuth Sector 2 (deg) </th>
    <th scope="column">Azimuth Sector 3 (deg) </th>
    <th scope="column">Downtilt Sector 1 (deg)</th>
    <th scope="column">Downtilt Sector 2 (deg) </th>
    <th scope="column">Downtilt Sector 3 (deg) </th>
    <th scope="column">ERP Sector 1 (W)</th>
    <th scope="column">ERP Sector 2 (W) </th>
    <th scope="column">ERP Sector 3 (W)</th>
    <th scope="column">Site Name</th>
    <th scope="column">Market</th>
    <th scope="column">CGI Sector 1</th>
    <th scope="column">CGI Sector 2 </th>
    <th scope="column">CGI Sector 3 </th>
    <th scope="column">Change Date</th>
  </tr>
  <?php 
  do { ?>
  <tr class="data2">
    <td class="data2"><a href="#"><?php echo $row_rs_ALL['Centennial Plan']; ?></a></td>
    <td class="data2"><?php echo $row_rs_ALL['Technology']; ?></td>
    <td class="data2"><?php echo $row_rs_ALL['Switch']; ?></td>
    <td class="data2"><?php echo $row_rs_ALL['Site ID']; ?></td>
    <td class="data2"><?php echo $row_rs_ALL['Cell Site Name']; ?></td>
    <td class="data2"><?php echo $row_rs_ALL['Dec Long']; ?></td>
    <td class="data2"><?php echo $row_rs_ALL['Dec Lat']; ?></td>
    <td class="data2"><?php echo $row_rs_ALL['Street']; ?></td>
    <td class="data2"><?php echo $row_rs_ALL['City']; ?></td>
    <td class="data2"><?php echo $row_rs_ALL['State']; ?></td>
    <td class="data2"><?php echo $row_rs_ALL['Zip']; ?></td>
    <td class="data2"><?php echo $row_rs_ALL['County/Parish']; ?></td>
    <td class="data2"><?php echo $row_rs_ALL['CR AGL (ft)']; ?></td>
	<?
HERE IS WHERE I WANT TO PUT THE FIRST IF STATEMENT...
if($row_rs_ALL['Antenna Model Sector 1'] = "*O or *X"){
	?>
    <td class="data2"><?php echo $row_rs_ALL['Antenna Model Sector 1']; ?></td>
    <td class="data2">&nbsp;</td>
    <td class="data2">&nbsp;</td>
	}
else
if($row_rs_ALL['Antenna Model Sector 1'] = "*Y"){
?>
    <td class="data2">&nbsp;</td>
    <td class="data2"><?php echo $row_rs_ALL['Antenna Model Sector 1']; ?></td>
    <td class="data2">&nbsp;</td>
                }
else 
if($row_rs_ALL['Antenna Model Sector 1'] = "*Z"){
?>
    <td class="data2">&nbsp;</td>
    <td class="data2">&nbsp;</td>
    <td class="data2"><?php echo $row_rs_ALL['Antenna Model Sector 1']; ?></td>
                }
    <td class="data2"><?php echo $row_rs_ALL['Azimuth Sector 1 (deg) ']; ?></td>
    <td class="data2">&nbsp;</td>
    <td class="data2">&nbsp;</td>
    <td class="data2"><?php echo $row_rs_ALL['Downtilt Sector 1 (deg)']; ?></td>
    <td class="data2">&nbsp;</td>
    <td class="data2">&nbsp;</td>
    <td class="data2"><?php echo $row_rs_ALL['ERP Sector 1 (W)']; ?></td>
    <td class="data2">&nbsp;</td>
    <td class="data2">&nbsp;</td>
    <td class="data2"><?php echo $row_rs_ALL['Site Name']; ?></td>
    <td class="data2"><?php echo $row_rs_ALL['Market']; ?></td>
    <td class="data2"><?php echo $row_rs_ALL['CGI Sector 1']; ?></td>
    <td class="data2">&nbsp;</td>
    <td class="data2">&nbsp;</td>
    <td class="data2"><?php echo $row_rs_ALL['Change Date']; ?></td>
  </tr>
  <?php } while ($row_rs_SiteName_OX = mysql_fetch_assoc($rs_SiteName_OX)); ?>
</table>

I realize the “if” statement is wrong, but it should give you a good impression of what it is I’m trying to accomplish.
Thanks for any feedback.

What errors are you getting?

If Statements are written similar to something below:

[php]<?
if($row_rs_ALL[‘Antenna Model Sector 1’] == “*O” || $row_rs_ALL[‘Antenna Model Sector 1’] == “*X”){
echo “Then Do This”;
}elseif($condtion2 == $condtion4){
echo “Then Do This Instead!”;
}else{
echo “None of the condtions matched!”;
}
?>[/php]

Notice the ==

== – is equal to
= – equals

<? if($row_rs_ALL['Antenna Model Sector 1'] == "*O" || $row_rs_ALL['Antenna Model Sector 1'] == "*X"){ echo "Then Do This"; }elseif($condtion2 == $condtion4){ echo "Then Do This Instead!"; }else{ echo "None of the condtions matched!"; } ?>
Is that if statement really valid? Can I use the “*” wildcard? Man that would be great.
I didn’t think I could get away with using the wildcard option, so here is what I came up with:

<td class="data2"><?php echo $row_rs_ALL['CR AGL (ft)']; ?></td>
	<?
	$site = $row_rs_ALL['Site ID'];
	$sector = explode(_,$site,3);
	if($sector = 'O'){
	?>
    <td class="data2"><?php echo $row_rs_ALL['Site ID']; ?></td>
    <td class="data2">&nbsp;</td>
    <td class="data2">&nbsp;</td>
	<?
	}else if($sector = 'X'){
	?>
    <td class="data2"><?php echo $row_rs_ALL['Site ID']; ?></td>
    <td class="data2">&nbsp;</td>
    <td class="data2">&nbsp;</td>
	<?
	}else if($sector = 'Y'){
	?>
	<td class="data2">&nbsp;</td>
	<td class="data2"><?php echo $row_rs_ALL['Site ID']; ?></td>
	<td class="data2">&nbsp;</td>
	<?
	}
	?>
    <td class="data2"><?php echo $row_rs_ALL['Azimuth Sector 1 (deg) ']; ?></td>

That was just a snippet of the file (the part I’m working on anyhow).
I get no error messages, but all of the data seems to appear in the first

. I think I know what the problem is, or at least one of the problems. I am using the explode function “explode(_,$site,3);” but my concern is that some of the Site Id’s have less than 2 _'s and some might have more than 2 _‘s. I am almost certain that what I need to accomplish (searching for the last character of Site Id) is in the string functions somewhere, but I havent’ found it yet.
I hope this clarifies things a little more.
Thank you for the prompt reply.
Sponsor our Newsletter | Privacy Policy | Terms of Service