Jump to content

Annoying Problem


Schlo_50

Recommended Posts

Hi guys,

 

I have a script that shows up details of vacancies and also two links that when clicked will add the details to a temporary address book. What im trying to achieve is, if the vacancies details have already been added to the temporary file I don't want the links to be displayed.

 

I have kind of managed to do this but because the snippet that checks to see if the details have already been added lies within a foreach() loop which throws out multiple links etc.

 

elseif($_GET['action'] == "View_Vacancy"){
	if(isset($_GET['vid'])){
		$cid = $_GET['vid'];
	}
	$file = file("data/vacancies.DAT");
	foreach($file as $key => $val){
		$data[$i] = explode("|", $val);
		if(trim($data[$i][0]) == $cid){
			list($canid, $name, $company, $address, $town, $county, $postcode, $tel, $fax, $email, $title, $salary, $status, $desc, $recruit, $fillopen) = explode("|", $val);
		}
	}
	if($status == "pending"){
		$ver = "<a href=\"?id=vacancies&action=Verify_Vacancy&vid=$canid\"><img src=\"images/verify.gif\" border=\"0\" /></a>";
	} else {
		$ver = "";
	}
	if(!isset($_GET['id'])){
		$out = file_get_contents("templates/print_vac_view.htm");
	} else {
		$out = file_get_contents("templates/vac_view.php");
	}

	$des = get_des($canid);
	$out = str_replace("[name]", $name, $out);
	$out = str_replace("[company]", $company, $out);
	$out = str_replace("[address]", $address, $out);
	$out = str_replace("[town]", $town, $out);
	$out = str_replace("[county]", $county, $out);
	echo $out;

////////////////////////////////CHecking for matches on the first link here
	$fileb = file("data/clients.DAT");
	foreach($fileb as $keyb => $valb){
		$datab[$keyb] = explode("|", $valb);
		$matchb = $datab[$keyb][0];

		if ($cid == $matchb){
		print "Already Added Head Office.";
	} 
else {
print "<div align=\"right\"><font color=\"#00CC33\">+</font> <a href=\"?id=clients&action=New_Client&vid=$canid\">Head Office</a></div>";
}
}
////////////////////////////////CHecking for matches on the second link here		
	$filec = file("data/sub_clients.DAT");
	foreach($filec as $keyc => $valc){
		$datac[$keyc] = explode("|", $valc);
		$matchc = $datac[$keyc][0];

		if ($_GET['vid'] == $matchc){
		print "Already Added Sub Office.";
	}
 else {
print "<div align=\"right\"><font color=\"#00CC33\">+</font> <a href=\"?id=clients&action=Add_Sub&vid=$canid\">Sub Office (Gen)</a></div>";
}		
}
}

Link to comment
https://forums.phpfreaks.com/topic/111078-annoying-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.