thekingfofa
New Member
Hii all
i am new at php and i did this script to get all messages from cometchat tables and be able to empty the table because it is getting bigger and bigger with time
here is the code it is very simple
sorry i have no time to improve it i just wanna share my work with u
Go vbteam ur are the best site
i am new at php and i did this script to get all messages from cometchat tables and be able to empty the table because it is getting bigger and bigger with time
here is the code it is very simple
sorry i have no time to improve it i just wanna share my work with u
PHP:
<title>Cometchat show and delete</title>
<form name="fcicafe.com" method="post" action="<?php echo $PHP_SELF;?>">
<input type="submit" name="delete" id="delete" value="delete">
</form>
<?php
$conn = mysql_connect("localhost", "username", "password");
if (!$conn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}
if (!mysql_select_db("database")) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}
if(!isset($_POST['delete']))
{
$sql = "SELECT fromuser.username, touser.username, cometchat.message
FROM cometchat
LEFT JOIN user AS fromuser ON ( fromuser.userid = cometchat.from )
LEFT JOIN user AS touser ON ( touser.userid = cometchat.to ) ";
$result = mysql_query($sql);
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
echo "<table border=\"1\">
<td scope=\"col\" >From</td>
<td scope=\"col\">To</td>
<td scope=\"col\">Message</td>";
while ($row = mysql_fetch_array($result)) {
echo"<tr>";
echo "<td>".$row[0]."</td>";
echo "<td>".$row[1]."</td>";
echo "<td>".$row[2]."</td>";
echo"</tr>";
}
echo "</table>";
mysql_free_result($result);
}
else
{
$sql = "TRUNCATE `cometchat`;";
$result = mysql_query($sql);
if($result)
echo "Deleted Successfully :)";
else
echo "Error :(";
}
?>