I'm new to php, as my question will probably clearly show.

I'm writing a simple program to track bills, and one thing I'm trying to do is include a "Find text that contains" box that will highlight certain fields in my table that match the search. The code I've written and thought should work... broke it. Completely.

Any help at all figuring out where I've gone wrong would greatly greatly appreciated. The pertinent block of code is:

$action = $_POST['action'];

	while ($action == 'Submit') {
	
		$myarray = array();
		$myelement = $item_value."*".$amount_value."*\n";
		array_push($myarray, $myelement);
	
		$array_counter = $i - 1;  //To make sure when get element 0 in the array!
	
		list($item_value, $amount_value) = explode("*", $myelement[$array_counter]);
		
		$pos = strpos($myarray, $targetstring)
		
		
		if($pos !== $targetstring) {
		
			print "<td><input type=text name=$item_name value=$item_value></td>";
			print "<td><input type=text name=$amount_name value=$amount_value></td>";
	
			else {
				print "<td><input type=text name=$item_name value=$item_value style=\"background-color: Yellow;\"></td>\n";
				print "<td><input type=text name=$amount_name value=$amount_value style=\"background-color: Yellow;\"></td>\n";
			}
		}
	}

Can't see what's the point of using arrays here:

$action = $_POST['action'];
if ($action == 'Submit') {
  if(strpos($item_value."*".$amount_value, $targetstring) !== FALSE) {
    print "<td><input type=text name=$item_name value=$item_value></td>";
    print "<td><input type=text name=$amount_name value=$amount_value></td>";
  } else {
    print "<td><input type=text name=$item_name value=$item_value style=\"background-color: Yellow;\"></td>\n";
    print "<td><input type=text name=$amount_name value=$amount_value style=\"background-color: Yellow;\"></td>\n";
  }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.