<?php

$q = strtolower($_GET["q"]);
if (!$q) return;
include 'db_connect.php';

if(isset($_GET['mode'])&&$_GET['mode']=='vendor')
{
	$items = mysqli_query($con,"SELECT compid,telephone FROM commst where type like 'VENDOR' order by compid ");



while($row = mysqli_fetch_array($items)) {
	if (strpos(strtolower($row['compid']), $q) !== false) {
		echo "$row[compid]|$row[telephone]\n";
		}
	}
	
}

if(isset($_GET['mode'])&&$_GET['mode']=='all')
{
	$items = mysqli_query($con,"SELECT compid,telephone, type FROM commst  order by compid ");


while($row = mysqli_fetch_array($items)) {
	if (strpos(strtolower($row['compid']), $q) !== false) {
		echo "$row[compid]|$row[type]\n";
		}
	}
	
}


else
{


$items = mysqli_query($con,"SELECT compid,name,cmpcity,conper,telephone,email,type FROM commst order by compid ");

while($row = mysqli_fetch_array($items)) {
	if (strpos(strtolower($row['compid']), $q) !== false) {
		echo "$row[compid]|$row[cmpcity]|$row[conper]|$row[telephone]|$row[email]|$row[name] | $row[type]\n";
		}
	}
}
mysqli_close($con);


?>