Advertisement
cuonic

search.php

Jun 20th, 2011
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.81 KB | None | 0 0
  1. <?php session_start(); ?>
  2. <?php if($_SESSION['loggedin'] !== "true") { header("Location: index.php"); exit; }
  3.  
  4. if(isset($_GET['q']))
  5. {
  6.     include("includes/mysql.php");
  7.    
  8.     $search_q = $_GET['q'];
  9.     $search_q = mysql_real_escape_string(htmlentities($search_q));
  10.    
  11.     $user_query = mysql_query("SELECT username FROM user_db WHERE username LIKE '$search_q%' OR email LIKE '$search_q%'");
  12.     $stock_query = mysql_query("SELECT stock, name FROm stocks_available WHERE stock LIKE '$search_q%' OR name LIKE '$search_q%'");
  13.    
  14.     if(mysql_num_rows($user_query) > 0)
  15.     {
  16.         if(mysql_num_rows($user_query) > 1)
  17.         {
  18.             // More than 1 result on user search
  19.            
  20.             $count = mysql_num_rows($user_query);
  21.            
  22.             $msg[] = "<b>User search :</b><br/>";
  23.             $msg[] = "<b>$count</b> results found";
  24.             $msg[] = "<br/><br/>";
  25.            
  26.             $i = 1;
  27.            
  28.             while(list($username) = mysql_fetch_row($user_query))
  29.             {
  30.                 $msg[] = $i . ". <b>$username</b> - <a href=\"userstocks.php?username=$username\">View this user's profile</a>";
  31.                 $msg[] = "<br/>";
  32.                 if($i === $count) { echo "<br/>"; } else { $i++; }
  33.             }
  34.            
  35.             echo "<br/><br/>";
  36.         }
  37.         else
  38.         {
  39.             // Only 1 result on user search
  40.            
  41.             $msg[] = "<b>User search :</b><br/>";
  42.             $msg[] = "<b>1</b> result found";
  43.             $msg[] = "<br/><br/>";
  44.            
  45.             list($username) = mysql_fetch_row($user_query);
  46.            
  47.             $msg[] = "1. <b>$username</b> - <a href=\"userstocks.php?username=$username\">View this user's profile</a><br/><br/>";
  48.         }
  49.     }
  50.     else
  51.     {
  52.         // 0 Results on user search
  53.         $msg[] = "<b>User search :</b><br/>";
  54.         $msg[] = "No results found !";
  55.         $msg[] = "<br/><br/>";
  56.     }
  57.     if(mysql_num_rows($stock_query) > 0)
  58.     {
  59.         if(mysql_num_rows($stock_query) > 1)
  60.         {
  61.             // More than 1 result on Stock Search
  62.            
  63.             $count = mysql_num_rows($stock_query);
  64.            
  65.             $msg[] = "<b>Stock search :</b><br/>";
  66.             $msg[] = "<b>$count</b> results found";
  67.             $msg[] = "<br/><br/>";
  68.            
  69.             $i = 1;
  70.            
  71.             while(list($stockcode, $stockname) = mysql_fetch_row($stock_query))
  72.             {
  73.                 $msg[] = $i . ". <b>$stockcode ($stockname)</b> - <a href=\"stockinfo.php?code=$stockcode\">View more info</a>";
  74.                 $msg[] = "<br/>";
  75.                 if($i === $count) { echo "<br/>"; } else { $i++; }
  76.             }  
  77.         }  
  78.         else
  79.         {
  80.             // Only 1 result on Stock Search
  81.            
  82.             $msg[] = "<b>Stock search :</b><br/>";
  83.             $msg[] = "<b>1</b> result found";
  84.             $msg[] = "<br/><br/>";
  85.            
  86.             list($stockcode, $stockname) = mysql_fetch_row($stock_query);
  87.            
  88.             $msg[] = "1. <b>$stockcode ($stockname)</b> - <a href=\"stockinfo.php?code=$stockcode\">View more info</a>";
  89.         }
  90.     }
  91.     else
  92.     {
  93.         // 0 Results on stock search
  94.         $msg[] = "<b>Stock search :</b><br/>";
  95.         $msg[] = "No results found !";
  96.     }
  97. }
  98.  
  99. ?>
  100. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  101. <html xmlns="http://www.w3.org/1999/xhtml">
  102. <head>
  103. <title>VirtualTrader</title>
  104. <meta http-equiv="Content-Language" content="English" />
  105. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  106. <link rel="stylesheet" type="text/css" href="style.css" media="screen" />
  107. </head>
  108. <body>
  109.  
  110. <div id="wrap">
  111.  
  112. <div id="header">
  113. <h1><img src="images/logo.png" alt="" width="425" height="62" /></h1>
  114. </div>
  115.  
  116. <div id="top"> </div>
  117. <?php include("includes/menu.php"); ?>
  118. <div id="content">
  119. <div class="left">
  120.  
  121. <h2>Search<?php if(isset($search_q)) { echo " - $search_q"; } ?></h2>
  122. <div class="articles">
  123. <?php if(isset($msg)) { foreach($msg as $mssg) { echo $mssg; } echo "<br/><br/>"; } ?>
  124. <form method="get" action="search.php"><input type="text" name="q" maxlength="30" />  <input type="submit" value="Search >" /></form>
  125. </div>
  126. </div>
  127.  
  128. <?php include("includes/sidebar.php"); ?>
  129. <div style="clear: both;"> </div>
  130. </div>
  131.  
  132. <div id="bottom"> </div>
  133. <?php include("includes/footer.php"); ?>
  134. </div>
  135.  
  136. </body>
  137. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement