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

  if($_GET['mode']=='buyercode'){
	  
	  $items = mysqli_query($con,"SELECT compid, name, address, cmpcity, pincode, rtmst, rtvalue, discount, broker, ftype  FROM commst");
   
	  while($row = mysqli_fetch_array($items)) 
	  {
		  echo $row[compid]."|".$row[name]."|".$row[address]."|".$row[cmpcity]."|".$row[pincode]."|".$row[rtmst]."|".$row[rtvalue]."|".$row[discount]."|".$row[broker]."|".$row[ftype]."\n";
	   
	  }
  }

  else if($_GET['mode']=='agentcode'){
	  
	  $items = mysqli_query($con,"SELECT compid, name FROM commst ");
   
	  while($row = mysqli_fetch_array($items)) 
	  {
		if (strpos(strtolower($row['compid']), $q) !== false) 
		{
		  echo $row[compid]."|".$row[name]."\n";
		}
	  }
  }
  
  else if($_GET['mode']=='shipto'){
	  
	  $items = mysqli_query($con,"SELECT compid, state, statecode FROM commst ");
   
	  while($row = mysqli_fetch_array($items)) 
	  {
		if (strpos(strtolower($row['compid']), $q) !== false) 
		{
		  echo $row[compid]."|".$row[state]."|".$row[statecode]."\n";
		}
	  }
  }

  else{
	$items = mysqli_query($con,"SELECT compid, name, address, type, cmpcity, pincode, gstin FROM commst");
   
	  while($row = mysqli_fetch_array($items)) 
	  {
		if (strpos(strtolower($row['compid']), $q) !== false) 
		{
		  echo $row[compid]."|".$row[name]."|".$row[address]."|".$row[type]."|".$row[cmpcity]."|".$row[pincode]."|".$row[gstin]."\n";
		}
	  }
  }
  
mysqli_close($con);
?>