0

im working on a php-based system. one of its features is allows user to download an excel file containing all the information in one of my table in my database. my problem is, one data of that information is classified to other users. thus, i want to convert the output of that data into a string of asterisk.

<?PHP


 //MySQL Database Connect
 include 'datalogin.php'; 

 function cleanData(&$str)
 { 
 $str = preg_replace("/\t/", "\\t", $str); 
 $str = preg_replace("/\r?\n/", "\\n", $str); 
 if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"'; 
 }
 # filename for download 
$filename = "website_data_" . date('Ymd') . ".xls"; 
 header("Content-Disposition: attachment; filename=\"$filename\""); 
 header("Content-Type: application/vnd.ms-excel");  
 $flag = false;

 //$result = pg_query("SELECT * FROM data_mapping ORDER BY CE_Hostname") or die('Query     failed!'); 
/*$query = "SELECT * FROM data_mapping";

while(false !== ($row = pg_fetch_assoc($result))) {  



//while(false !== ($row = pg_fetch_assoc($result))) {  


//$result=mysql_query($query);

$row=mysql_fetch_array($result);
$row=mysql_fetch_assoc ($result);


//$row=$row['Cust_Segment'];
// foreach($data as $row) 

 # display field/column names as first row
 if(!$flag) { 
 echo implode("\t", array_keys($row)) . "\r\n"; 

 $flag = true;  
 }
 array_walk($row, 'cleanData'); 
 echo implode("\t",($row)) . "\r\n";  

 }
 */


 $sql = 'SELECT CE_Hostname, Cust_Segment, Cust_Site_Name, CE_WAN_IP_Addr,     CE_Bkp_IP_Addr, Cust_Name, Svc_Type, com_string FROM data_mapping';

 $result = mysql_query($sql);

 if (!$result) {
    echo "DB Error, could not query the database<br>";
    echo 'MySQL Error: ' . mysql_error();
    exit;
    }
echo "Hostname\t Group/System\t Site Name\t IP ADDR\t BKP IP ADDR\t System Name\t     Device Type\t Comm_String\r\n";
     while ($row = mysql_fetch_assoc($result)) {
    echo implode("\t",($row)) . "\r\n";  
    }

 mysql_free_result($result);


//exit; 

 ?>

i want to convert only the comm_string result. thanks.

  • 5
    Just do not select the classified user data? Select all columns but one: http://stackoverflow.com/questions/9122/select-all-columns-except-one-in-mysql – Daryl Gill Mar 18 '13 at 01:17
  • just output a fixed string of asterisks... `"********"` – scunliffe Mar 18 '13 at 01:19
  • the output in the excel file need to be shown in the form of a string of asterisk. but only the data that contains comm_string.not all data have comm_string – user3428185 Mar 18 '13 at 01:30

2 Answers2

0
$sql = 'SELECT CE_Hostname, Cust_Segment, Cust_Site_Name, CE_WAN_IP_Addr,     CE_Bkp_IP_Addr, Cust_Name, Svc_Type, com_string FROM data_mapping';

Can simply be updated to not included the classified field

$sql = 'SELECT CE_Hostname, Cust_Segment, Cust_Site_Name, CE_WAN_IP_Addr,     CE_Bkp_IP_Addr, Cust_Name, Svc_Type FROM data_mapping';

Or if you still want to show some value there without any change in your PHP code then you could do

$sql = 'SELECT CE_Hostname, Cust_Segment, Cust_Site_Name, CE_WAN_IP_Addr,     CE_Bkp_IP_Addr, Cust_Name, Svc_Type, 'SECRET' FROM data_mapping';

This will then show SECRET instead of that code

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
  • Hanky Panky, but i need to make the result shown in the row of data that have comm_string(not all data have comm_string). in the form of asterisk. – user3428185 Mar 18 '13 at 01:28
0

Try this:

while ($row = mysql_fetch_assoc($result))
{
    $row['Comm_String'] = preg_replace( '/./', '*', $row['Comm_String'] );
    echo implode("\t",($row)) . "\r\n";  
}
J.D. Pace
  • 586
  • 1
  • 3
  • 17