bobbybowyer Posted September 22, 2009 Share Posted September 22, 2009 A result that appears in some of my queries is ' -1.00 ' and i want to change it to 'N/A'. i can not edit the database because this value is required but i would like to use the same table elsewhere and replace the value. Link to comment https://forums.phpfreaks.com/topic/175090-solved-need-to-replace-data-from-mysql-query-using-php/ Share on other sites More sharing options...
Bricktop Posted September 22, 2009 Share Posted September 22, 2009 Hi bobbybowyer, Just use str_replace (http://us2.php.net/str_replace) i.e. $newoutput = str_replace("-1.00", "N/A", $output); echo $newoutput; The above example assumes $output is the variable you are using to display the data containing the -1.00 figure. Hope this helps Link to comment https://forums.phpfreaks.com/topic/175090-solved-need-to-replace-data-from-mysql-query-using-php/#findComment-922800 Share on other sites More sharing options...
bobbybowyer Posted September 22, 2009 Author Share Posted September 22, 2009 Sorry, i should have been more specific the result is displayed as a repeated region Link to comment https://forums.phpfreaks.com/topic/175090-solved-need-to-replace-data-from-mysql-query-using-php/#findComment-922804 Share on other sites More sharing options...
Bricktop Posted September 22, 2009 Share Posted September 22, 2009 Hi bobbybowyer, str_replace should work in most scenarios, are you able to post your code? Link to comment https://forums.phpfreaks.com/topic/175090-solved-need-to-replace-data-from-mysql-query-using-php/#findComment-922806 Share on other sites More sharing options...
bobbybowyer Posted September 22, 2009 Author Share Posted September 22, 2009 <?php require_once('Connections/bilz.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_bilz, $bilz); $query_Recordset1 = "SELECT tbldomainpricing.id, tbldomainpricing.extension, tbldomainpricing.`order`, tblpricing.type, tblpricing.relid, tblpricing.msetupfee, tblpricing.qsetupfee FROM tbldomainpricing, tblpricing WHERE tblpricing.relid = tbldomainpricing.id AND tblpricing.type = 'domainregister' "; $Recordset1 = mysql_query($query_Recordset1, $bilz) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <table width="280" border="0" class="data"> <tr> <td nowrap="nowrap">typeTLD</td> <td nowrap="nowrap">1 Year</td> <td nowrap="nowrap">2 Year</td> </tr> <?php do { ?> <tr> <td nowrap="nowrap"><?php echo $row_Recordset1['extension']; ?></td> <td nowrap="nowrap">$<?php echo $row_Recordset1['msetupfee']; ?></td> <td nowrap="nowrap">$<?php echo $row_Recordset1['qsetupfee']; ?></td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> </body> </html> <?php mysql_free_result($Recordset1); ?> Link to comment https://forums.phpfreaks.com/topic/175090-solved-need-to-replace-data-from-mysql-query-using-php/#findComment-922807 Share on other sites More sharing options...
Bricktop Posted September 22, 2009 Share Posted September 22, 2009 Hi bobbybowyer, So, taking $row_Recordset1['1setupfee'] as an example could you not just: <td nowrap="nowrap">$<?php $qsetupfee = str_replace("-1.00", "N/A",$row_Recordset1['qsetupfee']); echo $qsetupfee; ?></td> Link to comment https://forums.phpfreaks.com/topic/175090-solved-need-to-replace-data-from-mysql-query-using-php/#findComment-922810 Share on other sites More sharing options...
bobbybowyer Posted September 22, 2009 Author Share Posted September 22, 2009 thanks so much i have been pulling my hair out on this one Link to comment https://forums.phpfreaks.com/topic/175090-solved-need-to-replace-data-from-mysql-query-using-php/#findComment-922822 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.