...

View Full Version : Changing Table Data Display



user55
08-18-2007, 12:21 AM
Hi,

I have a several columns on an auto generated report.

On one column, the data that it displays is either "Y" or "N". Is there a way to make all the "Y"s display as an "X" and all the "N"s just display blank?

If so, how would I create something like that?

Any help is appreciated. Thanks!

============================

Sara

Inigoesdr
08-18-2007, 12:25 AM
You would have to show us your code, or at least part of it for any specific help, but this could be easily accomplished with an if switch or ternary.
ex.

$output = '';
if($string == 'Y')
{
$output = 'X';
}

// or
$output = ($string == 'Y' ? 'X' : '');

user55
08-18-2007, 12:52 AM
Hi,

Thanks for the reply. Here is the code:


<table border="0" cellpadding="4" cellspacing="1" bgcolor="#fff">

<tr>
<td class="one" >COL 1</td>
<td class="one" >COL 2</td>
<td class="one" >COL 3</td>

</tr>



<?php
$rowcount = 0;
$group1_current_row = 0;
$group2_current_row = 0;
$group3_current_row = 0;
$grouptotal_current_row = 0;
$isStart01 = 0;
$isStart02 = 0;
$isStart03 = 0;

while ($row = mysql_fetch_array($result)) {

if ($rowcount == 0) {
}
$newgroupindex = -1;
echo "<tr>";
if (($rowcount%2) == 0) {
$css_class = "\"other\"";
} else {
$css_class = "\"altrow\"";
}
$cellvalue = "" . $row[0] . "";
if ($cellvalue == "") {
$cellvalue = "&nbsp;";
}
echo "<td class=" . $css_class . " align=Default >" . $cellvalue . "</td>";
$cellvalue = "" . $row[1] . ""; //this is the one that displays either a "Y" or "N"
if ($cellvalue == "") {
$cellvalue = "&nbsp;";
}
echo "<td class=" . $css_class . " align=Default >" . $cellvalue . "</td>";
$cellvalue = "" . $row[2] . "";
if ($cellvalue == "") {
$cellvalue = "&nbsp;";
}

$newgroupindex = -1;
$rowcount = $rowcount + 1;
$isStart01++;
$isStart02++;
$isStart03++;
$isStart04++;
$isStart05++;
echo "</tr>";
}

?>



</table>

Inigoesdr
08-18-2007, 01:03 AM
Try this:


$cellvalue = ($row[1] == 'Y' ? 'X' : '');
/*
$cellvalue = "" . $row[1] . ""; //this is the one that displays either a "Y" or "N"
if ($cellvalue == "") {
$cellvalue = "&nbsp;";
}*/

You can remove the commented part if it works.

user55
08-18-2007, 01:13 AM
Hi,

I tried it, but I get the following error on that line:

Parse error: syntax error, unexpected ';'

Sara

Inigoesdr
08-18-2007, 01:41 AM
I forgot to close the parenthesis. :o

I edited the code in my previous post, try it and let me know. =]

user55
08-18-2007, 01:47 AM
Hi,

Not a problem. Thanks for all of your help! It works great now.

Sara



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum