ok, im working a blog type of site. and i want to add smilies to it, so i am using a the str_replace function on the page that out puts the data. like this:
<?php require_once('Connections/conn.php'); ?>
<?php
$currentPage = $HTTP_SERVER_VARS["PHP_SELF"];
$maxRows_m = 5;
$pageNum_m = 0;
if (isset($HTTP_GET_VARS['pageNum_m'])) {
$pageNum_m = $HTTP_GET_VARS['pageNum_m'];
}
$startRow_m = $pageNum_m * $maxRows_m;
mysql_select_db($database_conn, $conn);
$query_m = "SELECT * FROM blog ORDER BY id DESC";
$query_limit_m = sprintf("%s LIMIT %d, %d", $query_m, $startRow_m, $maxRows_m);
$m = mysql_query($query_limit_m, $conn) or die(mysql_error());
$row_m = mysql_fetch_assoc($m);
if (isset($HTTP_GET_VARS['totalRows_m'])) {
$totalRows_m = $HTTP_GET_VARS['totalRows_m'];
} else {
$all_m = mysql_query($query_m);
$totalRows_m = mysql_num_rows($all_m);
}
$totalPages_m = ceil($totalRows_m/$maxRows_m)-1;
$queryString_m = "";
if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
$params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_m") == false &&
stristr($param, "totalRows_m") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_m = "&" . implode("&", $newParams);
}
}
$queryString_m = sprintf("&totalRows_m=%d%s", $totalRows_m, $queryString_m);
?>
<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!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>
<title>News...</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<? $row_m['blog'] = str_replace("\n", "<br>", $row_m['blog']); ?>
<? $row_m['blog'] = str_replace(":)", "<img src='images/smile.gif'>", $row_m['blog']); ?>
<? $row_m['blog'] = str_replace(":D", "<img src='images/grin.gif'>", $row_m['blog']); ?>
<? $row_m['blog'] = str_replace(":wub:", "<img src='images/wub.gif'>", $row_m['blog']); ?>
<? $row_m['blog'] = str_replace("^_^", "<img src='images/happy.gif'>", $row_m['blog']); ?>
<? $row_m['blog'] = str_replace(":blink:", "<img src='images/blink.gif'>", $row_m['blog']); ?>
<? $row_m['blog'] = str_replace(":blush:", "<img src='images/blush.gif'>", $row_m['blog']); ?>
<? $row_m['blog'] = str_replace(":crazy:", "<img src='images/crazy.gif'>", $row_m['blog']); ?>
<? $row_m['blog'] = str_replace(":cry:", "<img src='images/cry2.gif'>", $row_m['blog']); ?>
<? $row_m['blog'] = str_replace(":hehe:", "<img src='images/hehe.gif'>", $row_m['blog']); ?>
<? $row_m['blog'] = str_replace(":huh:", "<img src='images/huh.gif'>", $row_m['blog']); ?>
<? $row_m['blog'] = str_replace(":haha:", "<img src='images/laugh.gif'>", $row_m['blog']); ?>
<? $row_m['blog'] = str_replace(":zZz:", "<img src='images/sleeping.gif'>", $row_m['blog']); ?>
<? $row_m['blog'] = str_replace(":sleepy:", "<img src='images/sleepy.gif'>", $row_m['blog']); ?>
<? $row_m['blog'] = str_replace(":P", "<img src='images/tongue.gif'>", $row_m['blog']); ?>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td valign="top"><div align="right">
<?php do { ?>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td colspan="2" class="top"><?php echo $row_m['title']; ?></td>
</tr>
<tr>
<td colspan="2" class="main"><?php echo $row_m['blog']; ?></td>
</tr>
<tr>
<td width="84%" class="bottom"> </td>
<td width="16%" class="bottom"><div align="center"><?php echo $row_m['date']; ?></div></td>
</tr>
</table>
<br />
<?php } while ($row_m = mysql_fetch_assoc($m)); ?>
<p class="pages"> <a href="<?php printf("%s?pageNum_m=%d%s", $currentPage, max(0, $pageNum_m - 1), $queryString_m); ?>">Previous</a>
| <a href="<?php printf("%s?pageNum_m=%d%s", $currentPage, min($totalPages_m, $pageNum_m + 1), $queryString_m); ?>">Next</a> </p>
</div></td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($m);
?>
the problem i have with this, is that its only doing it for one row, so i was told i should phase it into the MySQL database before i pull it out... but i dont know how this would be done... im still sort of a newbie at php. this is the page that inputs the data into the database.
<?php require_once('../Connections/conn.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
}
$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "insert")) {
$insertSQL = sprintf("INSERT INTO blog (id, title, blog, `date`) VALUES (%s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['id'], "int"),
GetSQLValueString($HTTP_POST_VARS['title'], "text"),
GetSQLValueString($HTTP_POST_VARS['blog'], "text"),
GetSQLValueString($HTTP_POST_VARS['date'], "text"));
mysql_select_db($database_conn, $conn);
$Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());
$insertGoTo = "../index.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_conn, $conn);
$query_a = "SELECT * FROM blog";
$a = mysql_query($query_a, $conn) or die(mysql_error());
$row_a = mysql_fetch_assoc($a);
$totalRows_a = mysql_num_rows($a);
?>
<html>
<head>
<title>Insert News</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<form action="<?php echo $editFormAction; ?>" method="POST" name="insert" id="insert">
<p>
<input name="id" type="hidden" id="id">
<br>
title:
<input name="title" type="text" id="title">
<br>
blog:<br>
<textarea name="blog" cols="60" rows="10" id="blog"></textarea>
<br>
<input name="date" type="hidden" id="date" value="<? echo gmdate('m.d.y g:ia \E\S\T', time() -18000) ?>">
<br>
<input type="submit" name="Submit" value="Submit">
</p>
<input type="hidden" name="MM_insert" value="insert">
</form></td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($a);
?>
if you could tell me how to do this i would be very grateful.