hi all,
i have a string for example:
$str="The annual general meeting is scheduled on ::date:: at ::time::.
you all are requested to be present on ::date:: at ::time::."

i store it in the Templates_T table in my DB. Template_ID =1 [for eg.] now this format can be used further for drafting letters or creating newsletters etc..

Now in newsletters.php page for every ::date:: and ::time:: instance, for Template_ID 1 , i load textboxes in array for date[<input type =text name="dispdate[]">] and <select NAME="hours[]" > </select> <select NAME="minutes[]" > </select>in array[] for time. user enters some date and time in the textboxes and <select> respectively. now while updating the content in DB it should go as:
Step 1 : select the entire content from Template_T where Template_ID=1
Step 2: modify the message and replace ::date:: and ::time:: with relevant textbox values , <select > values. some thing like below
$EntireContent="The annual general meeting is scheduled on 'ValueOfBoxInArray' at 'ValueOfSelectInArray'.
you all are requested to be present on 'ValueOfBoxInArray' at 'ValueOfSelectInArray'."
$sql=mysql_query("insert into mytable_t values('$EntireContent')");

how will i accomplish this?
Thanks

MySQL doesn't recognize arrays much less PHP arrays. You need to put one piece of information in each field. If you want the entire contents of an array to go into one field either serialize it or convert it to a string.

Your request sounds a bit confusing, but I did a quick project that accomplishes something that you may be able to at least work with.
Please note this took me about 15-20 mintes to complete and test..there is much more that could be done to this
(I also used a Simple Calendar Widget - Cross-Browser Javascript pop-up calendar by Anthony Garrett scw.js)

I have one page called newspage.php here is that page
** Note, I converted the date output from the default of 0000-00-00 to 00-00-0000**
connect to your DB

<?php require_once('Connections/phpForum.php'); ?>

<?php
mysql_select_db($database_phpForum, $phpForum);
$query_rsNews = "SELECT * FROM templates_t";
$rsNews = mysql_query($query_rsNews, $phpForum) or die(mysql_error());
$row_rsNews = mysql_fetch_assoc($rsNews);
$totalRows_rsNews = mysql_num_rows($rsNews);

Form to hold values

<form id="form1" name="form1" method="post" action="">
  <table width="554" border="0">
    <tr>
      <td width="54"><a href="modify.php?id=<? echo $row_rsNews['id'];?>" >[Modify]</a></td>
      <td width="490">&nbsp;</td>
    </tr>
    <tr>
      <td><input name="id" type="hidden" id="id" value="<?php echo $row_rsNews['id']; ?>" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><?php echo $row_rsNews['text']; ?> on 
     <? $e = strtotime($row_rsNews['date']); ?>

      <?php echo strftime('%m-%d-%Y', $e);  ?> at <?php echo $row_rsNews['time']; ?> <?php echo $row_rsNews['AMPM']; ?></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><?php echo $row_rsNews['text2']; ?> on <?php echo strftime('%m-%d-%Y', $e);  ?> at&nbsp; <?php echo $row_rsNews['time']; ?> <?php echo $row_rsNews['AMPM']; ?></td>
    </tr>
  </table>
</form>

end html

mysql_free_result($rsNews);

Notice that I am carrying across via the URL the "id" of the Record to modify.
On the modify page I use the following code to display the current record and update it

<?php require_once('Connections/phpForum.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 = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE templates_t SET `date`=%s, `time`=%s, AMPM=%s, text=%s, text2=%s WHERE id=%s",
                       GetSQLValueString($_POST['date'], "date"),
                       GetSQLValueString($_POST['time'], "date"),
                       GetSQLValueString($_POST['AMPM'], "text"),
                       GetSQLValueString($_POST['text'], "text"),
                       GetSQLValueString($_POST['text2'], "text"),
                       GetSQLValueString($_POST['id'], "int"));

  mysql_select_db($database_phpForum, $phpForum);
  $Result1 = mysql_query($updateSQL, $phpForum) or die(mysql_error());

  $updateGoTo = "newspage.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_rsModifyNews = "-1";
if (isset($_GET['id'])) {
  $colname_rsModifyNews = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_phpForum, $phpForum);
$query_rsModifyNews = sprintf("SELECT * FROM templates_t WHERE id = %s", $colname_rsModifyNews);
$rsModifyNews = mysql_query($query_rsModifyNews, $phpForum) or die(mysql_error());
$row_rsModifyNews = mysql_fetch_assoc($rsModifyNews);
$totalRows_rsModifyNews = mysql_num_rows($rsModifyNews);
?><!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=iso-8859-1" />
<title>Untitled Document</title>
<script type='text/JavaScript' src='scw.js'></script>

</head>

<body>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  <table width="591" border="0">
    <tr>
      <td width="585"><input name="id" type="hidden" id="id" value="<?php echo $row_rsModifyNews['id']; ?>" /><?php echo $row_rsModifyNews['id']; ?></td>
    </tr>
    <tr>
      <td><input name="text" type="text" id="text" value="<?php echo $row_rsModifyNews['text']; ?>" size="95" /></td>
    </tr>
    <tr>
      <td>on 
      <input name="date" type="text" id="date" value="
<?php 
if ($row_rsModifyNews['date']== "0000-00-00")
{
echo ''; 
}
else
if ($row_rsModifyNews['date'] != NULL )
{
echo $row_rsModifyNews['date'];
} ?>"  
/> 
        <img src='JobPosting/images/scw.gif' alt='Click Here' width="16" height="16" title='Click Here' onClick="scwShow(document.getElementById('date'),this);" /> at 
        <input name="time" type="text" id="time" value="<?php echo $row_rsModifyNews['time']; ?>" />
        &nbsp; &nbsp;&nbsp;
        <select name="AMPM" id="AMPM">
          <?php
do {  
?>
          <option value="<?php echo $row_rsModifyNews['AMPM']?>"><?php echo $row_rsModifyNews['AMPM']?></option>
          <?php
} while ($row_rsModifyNews = mysql_fetch_assoc($rsModifyNews));
  $rows = mysql_num_rows($rsModifyNews);
  if($rows > 0) {
      mysql_data_seek($rsModifyNews, 0);
      $row_rsModifyNews = mysql_fetch_assoc($rsModifyNews);
  }
?>
        </select></td>
    </tr>
    <tr>
      <td><p>
        <input name="text2" type="text" id="text2" value="<?php echo $row_rsModifyNews['text2']; ?>" size="95" />
        &nbsp; &nbsp;</p>        </td>
    </tr>
    <tr>
      <td><div align="center">
        <input type="submit" name="Submit" value="Update" />
      </div></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form1">
</form>
</body>
</html>
<?php
mysql_free_result($rsModifyNews);
?>

I can send you the javascript for the calendar if you wish..let me know

Edited 3 Years Ago by Dani: Formatting fixed

hi Jeni,
First of all THANKS for looking into the problem and trying out an example for me. now have a look to what i am actually doing...
i am passing the Template_ID in my href

FIRST OF ALL LOAD THE TEMPLATE CONTENT:

// Oracle 9i is my DB and I am using PEAR 

if ($Template_ID !='') {
    $sql="select TemplateName_VC, Header_Txt, Footer_Txt, Content_Txt from Templates_T where Template_ID='$Template_ID'";
    $rs=$db->getRow($sql,DB_FETCHMODE_ASSOC);

    $content=$rs['header_txt'].'<br>';
    $content.=$rs['content_txt'].'<br>';
    $content.=$rs['footer_txt'];

// find every instance of date  $Content_TX=explode("::date::",$content);
}

<?
    $Dstr = '::date::'; // DATE INSTANCE 
    $Tstr = '::time::'; // TIME INSTANCE
// find every instance of date and create textboxes 
    if(substr_count($content, $Dstr)>0) { 
    $date_string=implode('<INPUT TYPE="text" class=txtbox NAME="dispdate[]" style="width:60">', $Content_TX);
    } else {
        $date_string = $Content_TX;
    }
// find every instance of time and create <select>
    if(substr_count($content, $Tstr)>0) { 
    $time=explode("::time::",$date_string);
    $time_string=implode('<SELECT NAME="hours[]" class=sel><option value="">HH</option>'.$droplist.'</SELECT>&nbsp;: <SELECT NAME="minutes[]" class=sel><option value="">MM</option>'.$ttdroplist.'</SELECT>', $time);
    } else {

        $time_string="";
    }
?>
<script>
function SaveAndClose() {
         frm=document.mainform;
         frm.action="save_newsletter.php";
         frm.submit();
}

</script>
<table class="table" width="80%" cellspacing=0 cellpadding=1 nof=ly  border=1>
<INPUT TYPE="hidden" NAME="Template_ID" value="<?=$Template_ID?>">
<tr>
<td colspan="2"><INPUT TYPE="button" value="Preview " class="button" onclick="Previewwin();"></td>
</tr>
<tr id="toolbar">
    <td id="styleformat"><BR>
    <?=$time_string?>
    <BR>&nbsp;
    </td>
</tr>
<td colspan="2"><INPUT TYPE="button" value="SAVE" class="button" onclick="SaveAndClose();"></td>

</table>
////////////////// END OF newsletters.php ////////////////////////////////////////////

save_newsletters.php

Now here is the problem of coding .... i dont know how to code here .....

Can you help me here...????

BUT, again THANKS for the try you have done... i will surely try to get help from what you have coded...

---

Edited 3 Years Ago by pyTony: fixed formatting

This article has been dead for over six months. Start a new discussion instead.