PHP - Timed Querys
can you run a query says every 60 seconds with out refreshing the entire page? at the moment im using <meta http-equiv="refresh" content="60;url=login_success.php">
Similar TutorialsHi there im not quite sure where im going wrong here. I have 2 queries; the first selects all records in a table == Session username. The second selects all records in a table <> Session username Both work independently but when i try to compare a field in each table (The: PlanetName) it doesnt work. Im trying to make it so that if the same PlanetName is in the first query and the second in any of the records it will output an ID. Code: [Select] <?php $colname_Fleet = "-1"; if (isset($_SESSION['MM_Username'])) { $colname_Fleet = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']); } mysql_select_db($database_swb, $swb); $query_Fleet = sprintf("SELECT FleetName, PlanetName FROM fleet WHERE PlayerName = %s", GetSQLValueString($colname_Fleet, "text")); $Fleet = mysql_query($query_Fleet, $swb) or die(mysql_error()); $totalRows_Fleet = mysql_num_rows($Fleet); $colname_FleetE = "-1"; if (isset($_SESSION['MM_Username'])) { $colname_FleetE = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']); } mysql_select_db($database_swb, $swb); $query_FleetE = sprintf("SELECT FleetName, PlanetName FROM fleet WHERE PlayerName <> %s", GetSQLValueString($colname_FleetE, "text")); $FleetE = mysql_query($query_FleetE, $swb) or die(mysql_error()); $totalRows_FleetE = mysql_num_rows($FleetE); while ($row_FleetE = mysql_fetch_assoc($FleetE) && $row_Fleet = mysql_fetch_assoc($Fleet)){ if($row_Fleet['PlanetName'] == $row_FleetE['PlanetName']){ echo $row_Fleet['FleetName']; echo' '; }} ?> Any help would be appreciated. Thanks I have a while loop that is making a table 5 times for me. The issue that i am having is i need to run 5 different mysql query's for the 5 different tables that the loop is making for me. How would i go about doing this? Here is my code <? $i=1; while ( $i <= 5 ) { ?> <table width="600" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="414" height="35" colspan="5"><strong>Level <?=$i?></strong></td> </tr> <tr> <td height="25"><div align="center">Join Date</div></td> <td><div align="center">Member Name</div></td> <td><div align="center">Username</div></td> <td><div align="center">Free/Pro</div></td> <td><div align="center"></div></td> </tr> <? $level_one = mysql_query("select * from users where ref_by = '$username'"); while ($level_one_do = mysql_fetch_array($level_one)) { $status = $level_one_do['status']; if($status == 1) { $status_type = "Free"; } else { $status_type = "Pro"; } ?> <tr> <td height="35"><div align="center"></div></td> <td height="35"><div align="center"></div></td> <td height="35"><div align="center"> <?=$level_one_do['Username']?> </div></td> <td height="35"><div align="center"></div></td> <td height="35"><div align="center"><img src="images/email_forward-32.png" width="25" height="25"></div></td> </tr> <? } ?> </table> <? $i++; } ?> Hi, My site http://bittleships.com is a simple online battleships game. Theres a 1088 cell grid where each cell is a mysql database entry containing details wether its been clicked, if theres a boat in the location etc. the site usually loads all the querys in 0.3 seconds, but when 5 or more people are playing this easily hits 1+ seconds. The code that displays the grid is this: Code: [Select] echo("<center><span style='background-color:white;color:red;font-size:12'>$griderrormsg</span></center>"); } echo("<table width='20' border='0' cellspacing='0' cellpadding='0'"); for($i=1; $i<=32; $i=$i+1){ echo("<tr>"); for($j=1; $j<=34; $j=$j+1){ $c++; $cell = $c; $sql="SELECT * FROM grid WHERE `ID` = $cell"; $result=mysql_query($sql); $row = mysql_fetch_array( $result ); $clicked = $row['clicked']; if ($clicked == "1"){ echo("<td title='$j, $i'><img src='b.gif"); }elseif ($clicked == "2"){ //if the ship was hit $hitby = $row['user']; echo("<td title='$j, $i - Hit by $hitby.'><img src='h.gif"); }elseif ($clicked == "3"){ //if is chest $hitby = $row['user']; echo("<td title='$j, $i - $prevamount btc won by $hitby.'><img src='chest.gif"); }else{ echo("<td><a href='index.php?c=$c'><img src='g.gif"); } echo("' BORDER=0></td></a>"); } echo("</tr>"); } echo("</table>"); } Is there a better way of running this for it to run quicker? I have designed and created a ecommerce website that allows the user to add products to a shopping cart and for the admin to edit the inventory list. However i would like to have a navigational bar on the website where the user can choose a brand of product and the webpage shows only that brand. I know i can do this by using the WHERE command in a query however would i have to make a separate web page for each brand? Thanks Boldonglen Hello coders, I'm using this code to grab random results from a table and it works well but I need it to be a non-repeating event. Code: [Select] $offset_result = mysql_query( " SELECT FLOOR(RAND() * COUNT(*)) AS `offset` FROM `jobs_board` "); $offset_row = mysql_fetch_object( $offset_result ); $offset = $offset_row->offset; I'm using this query followed by the html which is a set of divs with inline echo statements for the various variables I've localised from the table. Then I'm repeating that process a number of times to create a small list (I wanted to use a single while loop but cant figure it out at the moment). Anways, how can I make it so each query is random but also not repeated? At the moment they are indeed random but sometimes one same entry will appear a number of times consecutively... Nice one guys, L-plate This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=320461.0 Hi Ive made a database with the option to kick someone for a certain amount of time but seems like I'm doing something wrong somewhere can anybody please assist
My full script is
(Admin panel)
<? include "./emoticon_replace1.php"; if ($_POST["DeletePost"]) { $id = $_POST["id"]; $query = "DELETE FROM ".$dbTable." WHERE id='".$id."'"; mysql_query($query); echo "ID removed from system: ".$id; } if ($_POST["BanIP"]) { $IP_To_Add = $_POST["ip"]; if(eregi("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $IP_To_Add)) { $sql = "INSERT INTO ".$IPBanTable." (ip) VALUES (\"$IP_To_Add\")"; $result = mysql_query($sql); } else { echo "Error: Not a valid IP: ".$IP_To_Add; } } if ($_POST["purge"]) { $query = "TRUNCATE TABLE ".$dbTable; mysql_query($query); echo "StringyChat purged"; } if(!$_POST["update"] || !$_POST["StringyChat_name"] || !$_POST["StringyChat_message"]) { } else { $id = $_POST["id"]; $name = $_POST["StringyChat_name"]; $message = $_POST["StringyChat_message"]; include("emoticon_replace.php"); $query = "UPDATE ".$dbTable." SET StringyChat_name='$name', StringyChat_message='$message' WHERE id='".$id."'"; $result = mysql_query($query, $db) or die("Invalid query: " . mysql_error()); } if ($_POST["EditPost"]) { $id = $_POST["id"]; $result = mysql_query("SELECT * FROM ".$dbTable." WHERE id='".$id."'", $db); $myrow = mysql_fetch_array($result); ?> <form name="StringyChat_form" method="POST" action="?mode=postman"> Name:<br> <input name="StringyChat_name" class="StringyChatFrm" type="text" size="20" maxlength="<? echo $name_size; ?>" value="<? echo $myrow["StringyChat_name"]?>"> <br> Message:<br> <textarea name="StringyChat_message" class="StringyChatFrm" cols="20" rows="4"><? echo $myrow["StringyChat_message"]?></textarea> <br> <input type="hidden" name="id" value="<? echo $id ?>"> <input name="update" class="StringyChatFrm" type="submit" value="Update"> </form> <? } ?> <a href="<? echo $_SERVER['REQUEST_URI']; ?>&m=purge">Purge StringyChat</a><br> <br> <? // Load up the last few posts. The number to load is defined by the "ShowPostNum" variable. $result = mysql_query("SELECT * FROM ".$dbTable." ORDER BY StringyChat_time DESC",$db); while ($myrow = mysql_fetch_array($result)) { $msg = $myrow["StringyChat_message"]; $msg = strip_tags($msg); $msg = eregi_replace("im#([a-z]{3})", "<img src=\"/stringychat/images/\\1.gif\" alt=\"emoticon\">",$msg); printf("<div class=\"StringyChatItem\"><h4>%s<br>\n", $myrow["StringyChat_name"]); printf("%s<p>\n",$myrow["StringyChat_ip"],"%s</p>\n"); printf("%s</h4>\n", date("H:i - d/m/y", $myrow["StringyChat_time"])); printf("%s</div>\n", $msg); if ($_POST["1h"]) { $mxitid1= $_POST["1h"]; if(eregi("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $IP_To_Add)) { $sql1 = "UPDATE ".$dbTable." SET unban_time = DATE_ADD(NOW(), INTERVAL 1 DAY) WHERE mxit_id = $mxitid1)"; $result1 = mysql_query($sq1l); } else { echo "Error: Cannot Kick: ".$IP_To_Add; } } function checkban($mxitid) { // querys database $q = mysql_query("SELECT 1 FROM ".$dbTable." WHERE unban_time > NOW() AND mxit_id = '$mxitid'",$db); $get = mysql_num_rows($q); // if found if ($get == "1") { // deny user access $r=mysql_fetch_array($q); die("You have been banned from this website until $r[legnth]. If you feel this is in error, please contact the webmaster at ."); } } ?> <form name="form<? echo $myrow["id"];?>" method="post" action="?mode=postman"> <input name="id" type="hidden" value="<? echo $myrow["id"];?>"> <input name="ip" type="hidden" value="<? echo $myrow["StringyChat_ip"];?>"> <input name="EditPost" type="submit" id="EditPost" value="Edit"> <input name="DeletePost" type="submit" id="DeletePost" value="Delete"> <input name="BanIP" type="submit" id="BanIP" value="Ban <? echo $myrow["StringyChat_ip"];?>"> <input name="1h" type="submit" id="1" value="Kick <? echo $myrow["mxit_id"];?>"> <input name="1d" type="submit" id="1d" value="Kick <? echo $myrow["StringyChat_ip"];?> for 24 hours "> <input name="7d" type="submit" id="7d" value="Kick <? echo $myrow["StringyChat_ip"];?> for 7 days "> </form> <? } ?>The part I added to the above script which is giving me pain is if ($_POST["1h"]) { $mxitid1= $_POST["1h"]; if(eregi("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $IP_To_Add)) { $sql1 = "UPDATE ".$dbTable." SET unban_time = DATE_ADD(NOW(), INTERVAL 1 DAY) WHERE mxit_id = $mxitid1)"; $result1 = mysql_query($sq1l); } else { echo "Error: Cannot Kick: ".$IP_To_Add; } } function checkban($mxitid) { // querys database $q = mysql_query("SELECT 1 FROM ".$dbTable." WHERE unban_time > NOW() AND mxit_id = '$mxitid'",$db); $get = mysql_num_rows($q); // if found if ($get == "1") { // deny user access $r=mysql_fetch_array($q); die("You have been banned from this website until $r[legnth]. If you feel this is in error, please contact the webmaster at ."); } }What I'm trying to do is to ban the person for 1 day. And by banning the person I want them to be blocked from my Index page from submitting a form (sending a message) which is stored as tik.php on my index page index.php <?php require_once('common.php'); include "ip-ban-time-limit.php"; checkban($_SERVER['HTTP_X_MXIT_USERID_R']); checkUser(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html> <head> <title>Galaxy Universe Chat</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> </head> <body><br> <div id="main"> <div class="caption">Galaxy Universe Chat</div> <div id="icon"> </div> <div id="result"> Hello <?php echo $_SESSION['userName']; ?> ! <br/> <div style="color:red"><b><p>Please keep it clean and in English or you will be banned!</p></b></div> <br> <?PHP include "./stringychat.inc.php"; require_once ( 'tik.php' ); ?> <br> <p><a href="index1.php">Refresh</a> | <a href="logout.php">Log Out</a></p> </div> <div id="source">Galaxy Wars chat @ cobusbo</div> </div> </body>Seems like I've been doing something wrong with my queries... This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=320284.0 Hello All, I am trying to create a png file (add to an existing png file). The code I have used to work without any issues until this afternoon. And I am 100% sure no one changed the code. When I try to access the logocreate.php now I get the following error Code: [Select] Warning: imagecreatefrompng(http://www.domain.com/logo/logo.png) [function.imagecreatefrompng]: failed to open stream: Connection timed out in /home/domain/public_html/logo/logocreate.php on line 8 When I access the http://www.domain.com/logo/logo.png from browser it works (image is available) Can anybody think of server side errors that may cause this? I have GD enabled and in PHP info shows allow_url_fopen On On allow_url_include Off Off Any help is greatly appreciated. Thanks. Hi guys im having trouble implementing functions into some buttons. I got a kicking script from the internet that looks as follow
I'm trying to post to a (SMF) simplemachines 2.0 forum using curl. I have logged in and I have tried sending all the fields, but when I try to post, I receive this message: "The following error or errors occurred while posting this message: Your session timed out while posting. Please try to re-submit your message." Do any of you know why this happens? Is the problem that when I visit the posting url, they give me a cookie that expires if I leave the posting url? I don't think the form is invalid, it looks like it has to do with the session. People at the simplemachines forum can have this problem when they try to post the ordinary way, but that is because of an inactivity period. Can my problem be because of a cookie? window.setInterval(function(){ s="<?= $lastid ?>"; $.post('../action/updatestream.php',{statusid:s.val()},function(e){ alert(e) }); }, 10000);Why isn't it working? Thanks, |