how to pass a php array to a sql query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bhakti
    New Member
    • Aug 2005
    • 2

    how to pass a php array to a sql query

    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
    [code=php]
    $EntireContent= "The annual general meeting is scheduled on 'ValueOfBoxInAr ray' at 'ValueOfSelectI nArray'.
    you all are requested to be present on 'ValueOfBoxInAr ray' at 'ValueOfSelectI nArray'."
    $sql=mysql_quer y("insert into mytable_t values('$Entire Content')");
    [/code]

    how will i accomplish this?

    Thanks in advance
    Last edited by Atli; Nov 12 '07, 04:31 PM. Reason: Added [code] tags.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    All you need is the str_replace function.

    You simply loop through each of the values you want to switch out, replacing them one at a time. Something like this:
    [code=php]
    foreach($dateAr ray as $date) {
    $str = str_replace(":: date::", $date, $str, 1);
    }
    [/code]

    Comment

    Working...