Kane250 Posted March 28, 2009 Share Posted March 28, 2009 Hi there. I am trying to do something fairly simple, but cannot get it. I have 4 textareas that have 4 corresponding tables in MySQL. I'm using explode to split the paragraph into sentences. Then I want foreach to take that array and insert each sentence into the appropriate table. I've been trying to write something here that would be flexible so I didn't have a ton of code, but the foreach is printing out my variables names as $variable, rather than calling them and returning each sentence in the array. I know this code doesnt do the actual insert..im just trying to prepare the statements. Can someone help me out? I'm completely stumped! <?php $para1content = ($_POST['firstParaText']); $para2content = ($_POST['secondParaText']); $para3content = ($_POST['thirdParaText']); $para4content = ($_POST['fourthParaText']); $allpara = array("para1", "para2", "para3", "para4"); $para1exploded = (explode('.', $para1content)); $para2exploded = (explode('.', $para2content)); $para3exploded = (explode('.', $para3content)); $para4exploded = (explode('.', $para4content)); $contentmarker = array('$para1exploded', '$para2exploded', '$para3exploded', '$para4exploded'); foreach ($allpara as $value) //This returns the name of the table to insert to { foreach ($contentmarker as $content) //This iterates through the exploded array { $sample_query = "INSERT INTO" . " " . $value . " (text, updated_at) VALUES ( " . $content . ", NOW())"; print $sample_query . "<br />"; }; }; ?> Link to comment https://forums.phpfreaks.com/topic/151489-can-you-print-out-and-call-variables-from-foreach/ Share on other sites More sharing options...
Philip Posted March 28, 2009 Share Posted March 28, 2009 $contentmarker = array('$para1exploded', '$para2exploded', '$para3exploded', '$para4exploded'); Single quotes do not execute variables and such. $contentmarker = array($para1exploded, $para2exploded, $para3exploded, $para4exploded); or $contentmarker = array("$para1exploded", "$para2exploded", "$para3exploded", "$para4exploded"); Link to comment https://forums.phpfreaks.com/topic/151489-can-you-print-out-and-call-variables-from-foreach/#findComment-795655 Share on other sites More sharing options...
Kane250 Posted March 28, 2009 Author Share Posted March 28, 2009 Thanks for the reply. The problem is that I don't want the variables to be executed until they are placed into the statement. If I remove the single quotes, the variable is being executed earlier and doesn't seem to be working properly. You know what I mean? Link to comment https://forums.phpfreaks.com/topic/151489-can-you-print-out-and-call-variables-from-foreach/#findComment-795803 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.