Jump to content

Recommended Posts

Hi guys

 

Can anyone see why this code is not working correctly?

 

What should happen:

on the website (see below) you will see a text area box. If you enter in more than two lines, the the results box should display both line. At present, it is only displaying the last line of test.

 

I am using a foreach to loop through the amount of values in the array. So it should be 2 lines = 2 loops.

But its only doing 2 line = 1 loop.

 

Any ideas please?

 

The website is:

http://www.adwordstool.co.uk/MT-SK2.php

Select 'standard' radio button and any of the check box's

 

 

function generate_standard_text(&$vars, &$adgroup_array)
{
$standard_text = ""; // init results string to return

if($vars['type'] == "standard"){

	foreach ($adgroup_array as $adgroup){
		$adgroup = trim($adgroup);					

		$standard_text = "$adgroup\n";

		if($vars['Phrase_Match']){
		$standard_text1 = ""$adgroup"\n";
			}

		if($vars['Exact_Match']){
		$standard_text2 = "[$adgroup]\n";
		}

		if($vars['Negative_Match']){
		$standard_text3 = "-$adgroup\n";
		}

}

}
return $standard_text.$standard_text1.$standard_text2.$standard_text3; // return results string
}

Link to comment
https://forums.phpfreaks.com/topic/117319-solved-help-with-foreach/
Share on other sites

I think the error is in the PHP code.

 

But here is the HTML code:

		<form method="post" name="form3" action="myexport.php">
			<table width="727" height="180" border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td background="GFX/wrapper/Result-box.jpg" align="center">
						<table width="707" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td align="center">
									<textarea name="data" cols="90" rows="8" class="smallText" id="results" wrap="off" >{$standard_text}</textarea>
								</td>
								</tr>
						</table>
					</td>
				</tr>
			</table>
			<br>
			<table width="727" border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td align="right">
						<select name="export_type">
							<option value="xls">XLS</option>
							<option value="csv">CSV</option>
						</select>
						<input type="submit" name="submit" value="Export" />
					</td>
				</tr>
			</table>
		</form>

 

Hope this makes it more clear

 

Cheers

No, samshel was asking where you call the function generate_standard_text(). What we really need to see is where $adground_array is defined. How are you turning the contents of that textbox (a string) to an array? Incidently, why are you passing your variables by reference?

O' Ok

 

does this help


$vars = array(
// Match types
"Negative_Match" => "",
"Exact_Match" => "",
"Phrase_Match" => "",

// Adgroup
"ad_group" => "",

// Types
"type" => "",
);


$vars['ad_group'] = sanitize($_POST['ad_group']);


if($vars['type'] == "standard")
	{	// generate results string and assign to template
		$smarty->assign("standard_text", generate_standard_text($vars, $adgroup_array));
	}

 

 

I am using smarty template to separate the PHP and HTML.

 

 

try

<?php
function generate_standard_text(&$vars, &$adgroup_array)
{
$standard_text = ""; // init results string to return

if($vars['type'] == "standard"){

	foreach ($adgroup_array as $adgroup){
		$adgroup = trim($adgroup);					

		$standard_text = "$adgroup\n";

		if($vars['Phrase_Match']){
		$standard_text1 = ""$adgroup"\n";
			}

		if($vars['Exact_Match']){
		$standard_text2 = "[$adgroup]\n";
		}

		if($vars['Negative_Match']){
		$standard_text3 = "-$adgroup\n";
		}
		$out .= $standard_text.$standard_text1.$standard_text2.$standard_text3;
}

}
return $out; // return results string
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.