Chatlogs search code

vRory

Unemployed.
May 4, 2011
447
69
Could someone code a lil search engine that you can enter a username and it shows the list of chatslogs

my current chatlogs page;
PHP:
<?php $pagerank = 3; include "templates/header.php"; ?>
   
    <div id="site_content">
    <?php include "templates/sidebar.php"; ?>
        <div id="content_container">
            <div id="content">
                <h1>{hotelName} Hotel ASE ::Command Logs</h1><hr/>
                <div align="center">
    <form method='post'>
        <table class=" table-bordered table-condensed">
            <tr>
               
    <table width="675">
        <tr>
            <td><b>Username</b></td>
            <td><b>Message</b></td>
            <td><b>Time/Date</b></td>
        </tr>
<?php                                // Make a MySQL Connection
                                $query = "SELECT * FROM chatlogs ORDER by id DESC limit 50";
   
                                $result = mysql_query($query) or die(mysql_error());
 
 
 
 
                                while($row = mysql_fetch_array($result))
                                {
                                echo("<tr>");
                                echo("<td>" . $row['user_name'] . "</td>");
                                echo("<td>" . $row['message'] . "</a></td>");
                               
                                // Now we convert the Unix timestamp to a humanley readable time
                                $timestamp = $row['timestamp'];
                                $date = date("D-m-Y H:i:s", $timestamp);
                               
                                echo("<td>$date</td></tr>");
                                }
                                ?>
 
</table>
        </div>
</center>
 
<?php include "templates/footer.php"; ?>
 

Ecko

23:37 [autobots] -!- eckostylez [[email protected]]
Nov 25, 2012
1,398
962
PHP:
<form method="post" action="">
 Search for:<input type="text" name="string" placeholder="Username">
 <input type="submit" value="Search">
 </form>
  <table width="100%"><tr><td><b>Username</b></td><td><b>Chat</b></td><td><b>Time/Date</b></td></tr>
 <?php
 if (isset($_POST['string']) == true){
 $q = mysql_query("SELECT * FROM `chatlogs` WHERE message LIKE '%$string%' OR user_name LIKE '%$string%' ORDER BY id desc") or die(mysql_error());
 while($row = mysql_fetch_array($q)){
 $string = strip_tags(mysql_real_escape_string($_POST['string']));
 
                                echo("<tr>");
                                echo("<td>" . $row['user_name'] . "</td>");
                                echo("<td>" . $row['message'] . "</a></td>");
                                $timestamp = $row['timestamp'];
                                $date = date("D-m-Y H:i:s", $timestamp);
                                
                                echo("<td>$date</td></tr>");
 
                                }
 
 
}
 ?></table>
 

vRory

Unemployed.
May 4, 2011
447
69
PHP:
<form method="post" action="">
Search for:<input type="text" name="string" placeholder="Username">
<input type="submit" value="Search">
</form>
  <table width="100%"><tr><td><b>Username</b></td><td><b>Chat</b></td><td><b>Time/Date</b></td></tr>
<?php
if (isset($_POST['string']) == true){
$q = mysql_query("SELECT * FROM `chatlogs` WHERE message LIKE '%$string%' OR user_name LIKE '%$string%' ORDER BY id desc") or die(mysql_error());
while($row = mysql_fetch_array($q)){
$string = strip_tags(mysql_real_escape_string($_POST['string']));
 
                                echo("<tr>");
                                echo("<td>" . $row['user_name'] . "</td>");
                                echo("<td>" . $row['message'] . "</a></td>");
                                $timestamp = $row['timestamp'];
                                $date = date("D-m-Y H:i:s", $timestamp);
                               
                                echo("<td>$date</td></tr>");
 
                                }
 
 
}
?></table>
This just shows the whole chatlogs from the db if i type anything such as 'HSDJBHJBJUKFJK' it shows all the chatlogs all the time.
 

Ecko

23:37 [autobots] -!- eckostylez [[email protected]]
Nov 25, 2012
1,398
962
This just shows the whole chatlogs from the db if i type anything such as 'HSDJBHJBJUKFJK' it shows all the chatlogs all the time.
Works perfectly fine for me:

b1ddd293.png
 

Users who are viewing this thread

Top