Search.php

Some searchable script for server side programming

  <!-- Header -->
  <?php include("components/header.php");
  include("components/db-connect.php") ?>
  <!-- .Header -->

  <?php

  if (isset($_POST['submit'])){

  if (isset($_POST['name'])){$query=$_POST['name'];}

  $sql = "SELECT * FROM pmd_users WHERE firmstate='on' and keywords LIKE '%" . $query .  "%' OR firmname LIKE '%" . $query .  "%'  OR business LIKE '%" . $query .  "%'  OR city LIKE '%" . $query .  "%' ";
  $data = $db->getAll($sql);
  $nofound_sql = "SELECT * FROM pmd_users WHERE selector='1'";
  $nofound_data = $db->getAll($nofound_sql);
}

 $str_query = strlen($query);

 if(!$data || $str_query == 0) {
	$find = 'no';
 }
 else {$find = 'yes';}

  ?>

  <?php
  //Не найдено - вывод магазина
  if($find == 'no') : ?>
   <? foreach ($nofound_data as $n_row) : ?>
 	  <div class="article">
    <a href="single.php?id=<?=$n_row['selector'] ?>"><div class="a_title"><?=$n_row['firmname'] ?></div></a>
    <div class="short">
      Адрес: <?=$n_row['address'] ?> <br>
      Телефон: <?=$n_row['phone'] ?><br>
      Город: <?=$n_row['city'] ?><br>
    </div>
    <div class="clear"></div>
  </div>
 <? endforeach; ?>
	<?php endif; ?>

<? if($find == 'yes') : ?>
  <?
   //Результы поиска

  foreach ($data as $row) : ?>
  	<div style="" class="article">

	<a href="single.php?id=<?=$row['selector'] ?>">
	<div class="thumbnail">
	<img src=".././sxema/<?=$row['selector'] ?>.jpg" />
	</div></a>

	<a href="single.php?id=<?=$row['selector'] ?>"><div class="a_title"><?=$row['firmname'] ?></div></a>

	<div class="description">
	<?=$row['metadescr']; ?>
	</div>

	<div class="short">
			<b>Адрес: </b><?=$row['address'] ?> <br>
			<b>Телефон: </b><?=$row['phone'] ?><br>

		</div>

		<a href="single.php?id=<?=$row['selector'] ?>" class="view-post-icon"></a>

		<div class="clear"></div>
	</div>
  <? endforeach; ?>
<? endif; ?>

 <!-- footer -->
 <?php include("components/footer.php"); ?>
 <!-- .footer -->

max

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>