Re: How to make it shorter and better?



AlGorr wrote:
Hello,,,

I don't know much about PHP+SQL but I have to find the better way to make my
query work and to be shorter and better.
All help will be appreciated.

//Check if IP exists in banIP
$res = mysql_query("SELECT ip FROM banIP WHERE ip =
'".$_SERVER['REMOTE_ADDR']."'");
$res = mysql_num_rows($res);
if($res != 0)
die;
mysql_free_result($res);

//Fetch Time
$timestamp = time();
$timeout = $timestamp - 900;
//Delete Users
$del = mysql_query("DELETE FROM caspionet WHERE timestamp<$timeout");

//Check if IP exists in caspionet
$res = mysql_query("SELECT ip FROM caspionet WHERE ip =
'".$_SERVER['REMOTE_ADDR']."'");
$res = mysql_num_rows($res);
if($res == 0){
//Insert User
$ins = mysql_query("INSERT INTO caspionet (timestamp, ip)
VALUES('$timestamp','".$_SERVER['REMOTE_ADDR']."')");
}
mysql_free_result($res);

//Fetch Users Online
$res = mysql_query("SELECT DISTINCT ip FROM caspionet");
while ($row = mysql_fetch_array($res, MYSQL_BOTH)){
print("IP:$row[0]");
}
mysql_free_result($res);

Thank you
A.K.



Please cross-post - don't multipost!

Answered in comp.databases.mysql.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.



Relevant Pages

  • How to make it shorter and better?
    ... query work and to be shorter and better. ... //Check if IP exists in caspionet ... $ins = mysql_query("INSERT INTO caspionet (timestamp, ...
    (comp.lang.php)
  • How to make it shorter and better?
    ... query work and to be shorter and better. ... //Check if IP exists in caspionet ... $ins = mysql_query("INSERT INTO caspionet (timestamp, ...
    (alt.php)
  • Re: optimizing Hash deletions
    ... This makes the list much shorter and no pruning is needed. ... you could just assemble the list of files that have a ... timestamp that is different and you would not need to do all that ...
    (comp.lang.ruby)
  • Re: Comparison of date/time
    ... >this query work. ... TimeStamp < from myTable) ... Brian Bushay (TeamB) ...
    (borland.public.delphi.database.ado)
  • Comparison of date/time
    ... The database is access 97 and the timestamp is of type "Date/Time" ... this query work. ...
    (borland.public.delphi.database.ado)