PHP - Css Stopping Next Page Loading
I have a script which registers people to a database, however it doing something very strange. Whenever I place it into even a single CSS div it adds the registration to the dabase but stops loading the next page (index.php)
I find this totally bizarre as I haven't seen anything like this behave before. With CSS affecting how PHP works. Especially when the CSS is not inside the <php> of <form> tags. Code: [Select] <?php include("connect.php"); if($_POST['submit']) { $username = mysql_real_escape_string(trim($_POST['username'])); $password = trim($_POST['password']); $password2 = trim($_POST['password2']); $email = mysql_real_escape_string(trim($_POST['email'])); $error = false; if(!isset($username) || empty($username)) { $error = "You need to enter a username."; } $query = mysql_query("SELECT id FROM users WHERE username = '".$username."' LIMIT 1"); if(mysql_num_rows($query) > 0 && !$error) { $error = "Sorry, that username is already taken!"; } if((!isset($password) || empty($password)) && !$error) { $error = "You need to enter a password."; } if((!isset($password2) || empty($password2)) && !$error) { $error = "You need to enter your password twice."; } if($password != $password2 && !$error) { $error = "The passwords you entered did not match."; } if((!isset($email) || empty($email)) && !$error) { $error = "You need to enter an email."; } if(preg_match("/[a-zA-Z0-9-.+]+@[a-zA-Z0-9-]+.[a-zA-Z]+/", $email) == 0 && !$error) { $error = "The email you entered is not valid."; } $query = mysql_query("SELECT id FROM users WHERE email = '".$email."' LIMIT 1"); if(mysql_num_rows($query) > 0 && !$error) { $error = "Sorry, that email is already in use!"; } if(!$error) { $query = mysql_query("INSERT INTO users (username, password, email) VALUES ('".$username."', '".mysql_real_escape_string(md5($password))."', '".$email."')"); if($query) { $message = "Hello ".$_POST['username'].",\r\n\r\nThanks for registering! We hope you enjoy your stay.\r\n\r\nThanks,\r\nJohn Doe"; $headers = "From: ".$website['name']." <".$website['email'].">\r\n"; mail($_POST['email'], "Welcome", $message, $headers); setcookie("user", mysql_insert_id(), $time); setcookie("pass", mysql_real_escape_string(md5($password)), $time); header("Location: index.php"); } else { $error = "There was a problem with the registration. Please try again."; } } } ?><html> <head> <title>Register</title> </head> <body> <form action="" method="post"> <?php if($error) echo "<span style=\"color:#ff0000;\">".$error."</span><br /><br />"; ?> <label for="username">Username: </label> <input type="text" name="username" value="<?php if($_POST['username']) echo $_POST['username']; ?>" /><br /> <label for="password">Password: </label> <input type="password" name="password" value="<?php if($_POST['password']) echo $_POST['password']; ?>" /><br /> <label for="password2">Retype Password: </label> <input type="password" name="password2" value="<?php if($_POST['password2']) echo $_POST['password2']; ?>" /><br /> <label for="email">Email: </label> <input type="text" name="email" value="<?php if($_POST['email']) echo $_POST['email']; ?>" /><br /><br /> <input type="submit" name="submit" value="Register" /> </form> </body> Similar TutorialsI seem to have a problem with a PHP page I made. When executed on the server, it loads with a filesize 0 and for some browsers, says it does not exist. I believe that the cause is because it is not parsing due to a syntax error. I've busted my @$$ over this code, trying to find the issue, but cannot find it. Here is the whole page's code on pastie: http://pastie.org/1064160 I have some issue with the website just created specifically http://ecolandscaping.co/index.php?m=3 and hosted on the 000webhosting.com. It loads the page slowly. Things what i have consideredto trie to improve better performance: * optimized CSS files * optimized MySQL queries with specifying the rows wanted (SELECT ID, IMAGE.....) * avoid to select an image saved as blob if not necessary etc. * made different image retrieving php files P.S. the website is small of size approx 700KB for loading. Problem is that not all the images (saved in MYSQL BLOB) are loaded successfully. Could anyone have a look and advice what else could cause the performance issue. P.S.S. I do take in account that this isthe free hosting and may cause some problems I have a PHP Page. It is doing a lot of site crawling, throughout a lot of loops. Basically it's getting a massive array together and it's huge. However, it's so big that PHP times out beyond belief. I mean there is no error or nothing. Google throws a major error about page not found, IE shows an internet connection error. It really times out big time. Even though it's not really "A LOT". Any advice on what to do in that situation. I can't show the site/code because of NDA, but was curious if someone had ever done that much work on a PHP page before to have it do that? What I'm trying to do is get a php file with content to load into my basic page template based on the page id, however it's not loading anything, however there are no errors coming up. I've looked everywhere I could find, and tried everything I could think of. I really could use some help on this. Below is the page template code and the code I'm trying to use to get the content to load up. page_templ.php Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" > <link rel="stylesheet" type="text/css" href="templates/content/style.css" > <!--This is the css used for IE because we need to correct some things for it.--> <!--[if IE]> <style type="text/css"> @import 'templates/content/styleIE.css'; </style> <![endif]--> </head> <body> <?php //We need to load our language files with our common text varibles require("content/langeng.php"); ?> <div id="header"> <? //Lets show the header. I use html where I can so smartphones load as little advanced code as possible require_once("header.php"); ?> </div> <div id="menu"> <?//Now our menu. require_once("menu.php"); ?> </div> <div id="mbody"> <?//Now the primary site content. //Load up our postvars.php file require_once("content/postvars.php"); ?> </div> </body> </html> postvars.php Code: [Select] <?php $id = $_POST["id"]; if ( $id == "home" ) { include 'main_c.php'; } elseif ( $id == "guides" ) { include 'guides_c.php'; } elseif ( $id == "trips" ) { include 'trips_c.php'; } ?> This should be an easy one but I'm looking for a bit of help. I'm using a php framework and using includes to bring different pieces of a website togethor onto the page. The top of the page uses a flash banner, then there are some simple text sections below. The banner is in it's own php file as well. Wondering if it's possible to have the banner NOT replay after each page load? I'm not sure if this is something I need to setup in the flash file, or if there is a way to do it in the php files? Basically, the banner is the same for all of the pages, and I want it (once loaded) to stay on the page while the details on the bottom change, WITHOUT going through the entire animation again. Make sense? here's the page as it stands now so you can get a better idea what I'm trying to do. http://www.getmoreimpact.com/index.php again not sure if this needs to be done in the flash side, or the php? Any ideas are better than what I've got! Thanks in advance Hi, I'm new. I have been searching for this, but couldn't find my answer ... I've got a form on page A, with its 'action' attribute set to page B.php. Page B does nothing but process the form data & put it in a database. At the bottom of B.php there's a header redirect to page C. My problem is that page B shows up briefly in the browser, looking all blank and weird. Is there a sensible way around this? I just want it to do its stuff in the background. I realise I should be Ajaxing it all but, apart from the fact that I struggle with Ajax operations longer than a couple of lines, it's important that the site should work without javascript. I HOPE this is a really easy one! Thanks <?xml-stylesheet href="/player.xsl" type="text/xsl"?> <config> <auto_start>false</auto_start> <player_skin>/test.swf</player_skin> <main_title>Test</main_title> <playlist_title>PLAYLIST</playlist_title> <time_text>TOTAL TIME</time_text> <pan_labels>L,R</pan_labels> <scroller_speed>1</scroller_speed> <scroller_marquee_content>#TRACK_NAME#</scroller_marquee_content> <repeat_is_enabled>false</repeat_is_enabled> <shuffle_is_enabled>false</shuffle_is_enabled> <default_volume>75</default_volume> <default_pan>0</default_pan> <play_list> <item>test.mp3;Test Soundtrack</item> </play_list> </config>Hi, The above code is from an XML file and I added the <?xml line of code to the XML file, but doing so causes the whole page to no longer display the track information (just blank). Is there there a way I could modify that text to try and call it another way? Thanks Edited by hexcode, 16 July 2014 - 02:52 PM. So long story short im trying to read a text file line by line and do a cpl db tests agains that one line my file size is about 1300 lines long so I cut it down to 600 and the page is stil stuck loading, can anyone tell me why, my code is below.: (it was working fine I must have just changed something without knowing it) Code: [Select] <?php include ("include/session.php"); $file_handle = fopen ( "To Do.txt", "rb" ); while ( ! feof ( $file_handle ) ) { $line_of_text = fgets ( $file_handle ); $parts = explode ( '=', $line_of_text ); //get the course infomation //Examples: //$Course_info[0] = GEOL //$Course_info[1] = 1002 //$title = Introduction To Geology $Course_info = explode ( ' ', $parts [0] ); $length = strlen ( $Course_info [0] ) + strlen ( $Course_info [1] ) + 2; $title = substr ( $parts [0], $length ); //check to see if this course is already in the database $sql = "SELECT * FROM courses WHERE course = '$Course_info[0]' AND code = '$Course_info[1]'"; $res = mysql_query ( $sql ) or die ( mysql_error () ); if (mysql_num_rows ( $res ) == 0) { //course doesnt exist //lets get the program ID for this course $id_sql = "SELECT id FROM catagories WHERE code = '$course_info[0]'"; $res = mysql_query($id_sql) or die (mysql_error()); $row = mysql_fetch_array ( $res ); echo $row ['code']; } else { //course is already in the database } exit (); } Hello Coders, Iam in a confused situation. I made a php script & in that script i want to check how much time (in seconds) the page is taking to fetch the content from the server. If the time is greater than to i defined time then i want to show a error message to the users. Anybody can give me ideas ..................... ?? Apologies if the title is quite vague, I suppose I am looking for some general advice on why some pages I write in PHP, which contain MySQL queries, might be running a bit slow. The following page takes up to 3 seconds to display:
<?php session_start(); include('admin/user.php'); $connection = mysql_connect("$host","$user","$password") or die(mysql_error()); mysql_select_db("$txt_db_name",$connection) or die(mysql_error()); $id = $_REQUEST['id']; // MATCH INFO $get_details = mysql_query(" SELECT MatchDateTime AS date, DATE_FORMAT(MatchDateTime, '%Y-%m-%d') AS formatdate FROM tplss_matches WHERE MatchID = '$id' LIMIT 1",$connection) or die(mysql_error()); $factsdata = mysql_fetch_array($get_details); mysql_free_result($get_details); $matchdate = $factsdata['date']; $matchdate2 = $factsdata['formatdate']; // -----------SHOW FACTS ABOUT THE STARTING LINEUP--------- echo" <h5>Appearances & Goals To Date</h5> <table width=100%>"; $get_starters = mysql_query(" SELECT P.PlayerID AS playerid, CONCAT(P.PlayerFirstName, ' ', P.PlayerLastName) AS name, P.PlayerNationID AS nation, P.PlayerPositionID as pos FROM tplss_players P, tplss_appearances A WHERE A.AppearancePlayerID = P.PlayerID AND A.AppearanceMatchID = '$id' ORDER BY P.PlayerPositionID ASC ",$connection) or die(mysql_error()); $get_subbies = mysql_query(" SELECT P.PlayerID AS playerid, CONCAT(P.PlayerFirstName, ' ', P.PlayerLastName) AS name, P.PlayerNationID AS nation, P.PlayerPositionID as pos FROM tplss_players P, tplss_substitutions S WHERE S.SubstitutionPlayerIDIn = P.PlayerID AND S.SubstitutionMatchID = '$id' ORDER BY P.PlayerPositionID ASC ",$connection) or die(mysql_error()); while($combstarters = mysql_fetch_array($get_starters)) { echo"<tr>"; echo"<td><a href=\"player.php?id=$combstarters[playerid]\">$combstarters[name]</a>"; if($combstarters['pos'] == 1) { echo" (GK)"; } echo"</td>"; $combpid = $combstarters['playerid']; echo" <td align=\"left\" style=\"vertical-align: middle;\"> <img src=\"images/flag_$combstarters[nation].jpg\" border=1> </td> "; $get_comb_apps = mysql_query("SELECT COUNT(A.AppearancePlayerID) AS apps FROM tplss_appearances A, tplss_matches M WHERE A.AppearancePlayerID = '$combpid' AND A.AppearanceMatchID = M.MatchID AND M.MatchDateTime <= '$matchdate' ",$connection) or die(mysql_error()); $get_comb_ins = mysql_query("SELECT COUNT(S.SubstitutionPlayerIDIn) AS ins FROM tplss_substitutions S, tplss_matches M WHERE S.SubstitutionPlayerIDIn = '$combpid' AND S.SubstitutionMatchID = M.MatchID AND M.MatchDateTime <= '$matchdate' ",$connection) or die(mysql_error()); while($combdata = mysql_fetch_array($get_comb_apps)) { while($idata = mysql_fetch_array($get_comb_ins)) { $totalapps = $combdata['apps'] + $idata['ins']; if($totalapps == 1) { echo"<td>$totalapps app (debut)</td>"; } else { echo"<td>$totalapps apps</td>"; } } mysql_free_result($get_comb_ins); } mysql_free_result($get_comb_apps); $get_goals_all = mysql_query(" SELECT COUNT(G.GoalPlayerID) AS total_goals FROM tplss_goals G, tplss_matches M WHERE G.GoalPlayerID = '$combpid' AND G.GoalMatchID = M.MatchID AND M.MatchDateTime <= '$matchdate' AND G.GoalOwn != 1 GROUP BY G.GoalPlayerID ",$connection) or die(mysql_error()); if(mysql_num_rows($get_goals_all) == 0) { echo"<td> - </td>"; } while($combgoals = mysql_fetch_array($get_goals_all)) { if($combgoals['total_goals'] == 1) { echo"<td>$combgoals[total_goals] goal</td>"; } else { echo"<td>$combgoals[total_goals] goals</td>"; } } mysql_free_result($get_goals_all); echo"</tr>"; } while($combsubbies = mysql_fetch_array($get_subbies)) { echo"<tr>"; echo"<td><a href=\"player.php?id=$combsubbies[playerid]\">$combsubbies[name]</a> (sub)"; if($combsubbies['pos'] == 1) { echo" (GK)"; } echo"</td>"; $combpid = $combsubbies['playerid']; echo" <td align=\"left\" style=\"vertical-align: middle;\"> <img src=\"images/flag_$combsubbies[nation].jpg\" border=1> </td> "; $get_comb_apps = mysql_query("SELECT COUNT(A.AppearancePlayerID) AS apps FROM tplss_appearances A, tplss_matches M WHERE A.AppearancePlayerID = '$combpid' AND A.AppearanceMatchID = M.MatchID AND M.MatchDateTime <= '$matchdate' ",$connection) or die(mysql_error()); $get_comb_ins = mysql_query("SELECT COUNT(S.SubstitutionPlayerIDIn) AS ins FROM tplss_substitutions S, tplss_matches M WHERE S.SubstitutionPlayerIDIn = '$combpid' AND S.SubstitutionMatchID = M.MatchID AND M.MatchDateTime <= '$matchdate' ",$connection) or die(mysql_error()); while($combdata = mysql_fetch_array($get_comb_apps)) { while($idata = mysql_fetch_array($get_comb_ins)) { $totalapps = $combdata['apps'] + $idata['ins']; if($totalapps == 1) { echo"<td>$totalapps app (debut)</td>"; } else { echo"<td>$totalapps apps</td>"; } } mysql_free_result($get_comb_ins); } mysql_free_result($get_comb_apps); $get_goals_all = mysql_query(" SELECT COUNT(G.GoalPlayerID) AS total_goals FROM tplss_goals G, tplss_matches M WHERE G.GoalPlayerID = '$combpid' AND G.GoalMatchID = M.MatchID AND M.MatchDateTime <= '$matchdate' AND G.GoalOwn != 1 GROUP BY G.GoalPlayerID ",$connection) or die(mysql_error()); if(mysql_num_rows($get_goals_all) == 0) { echo"<td> - </td>"; } while($combgoals = mysql_fetch_array($get_goals_all)) { if($combgoals['total_goals'] == 1) { echo"<td>$combgoals[total_goals] goal</td>"; } else { echo"<td>$combgoals[total_goals] goals</td>"; } } mysql_free_result($get_goals_all); echo"</tr>"; } echo"</table>"; // -----------SHOW FACTS ABOUT THE STARTING LINEUP--------- echo"<br> <h5>Starting Lineup</h5> <table width=100%>"; // GET YOUNGEST PLAYER IN STARTING LINEUP $get_youngest_player = mysql_query(" SELECT P.PlayerDOB AS dob, DATE_FORMAT(P.PlayerDOB, '%d/%m/%Y') AS birth, CONCAT(P.PlayerFirstName, ' ', P.PlayerLastName) AS name, P.PlayerID AS id FROM tplss_players P, tplss_appearances A, tplss_matches M WHERE P.PlayerID = A.AppearancePlayerID AND A.AppearanceMatchID = M.MatchID AND M.MatchDateTime = '$matchdate' ORDER BY dob DESC LIMIT 0,1 ",$connection) or die(mysql_error()); while($youngest = mysql_fetch_array($get_youngest_player)) { echo"<tr>"; $dob = $youngest['dob']; echo"<td width=30%>Youngest Player:</td><td width=70%><a href=\"player.php?id=$youngest[id]\">$youngest[name]</a> ("; $now = strtotime("$matchdate"); $your_date = strtotime("$dob"); $datediff_days = $now - $your_date; $datediff_years = ($now - $your_date) / 365; $days = floor($datediff_days/(60*60*24)); $years = floor($datediff_years/(60*60*24)); $remainder = floor($datediff_days/(60*60*24)) - (floor($datediff_years/(60*60*24)) * 365); echo"$years years $remainder days)</td> </tr> "; } mysql_free_result($get_youngest_player); // GET OLDEST PLAYER IN STARTING LINEUP $get_oldest_player = mysql_query(" SELECT P.PlayerDOB AS dob, DATE_FORMAT(P.PlayerDOB, '%d/%m/%Y') AS birth, CONCAT(P.PlayerFirstName, ' ', P.PlayerLastName) AS name, P.PlayerID AS id FROM tplss_players P, tplss_appearances A, tplss_matches M WHERE P.PlayerID = A.AppearancePlayerID AND A.AppearanceMatchID = M.MatchID AND M.MatchDateTime = '$matchdate' ORDER BY dob ASC LIMIT 0,1 ",$connection) or die(mysql_error()); while($oldest = mysql_fetch_array($get_oldest_player)) { echo"<tr>"; $dob = $oldest['dob']; echo"<td width=30%>Oldest Player:</td><td width=70%><a href=\"player.php?id=$oldest[id]\">$oldest[name]</a> ("; $now = strtotime("$matchdate"); $your_date = strtotime("$dob"); $datediff_days = $now - $your_date; $datediff_years = ($now - $your_date) / 365; $days = floor($datediff_days/(60*60*24)); $years = floor($datediff_years/(60*60*24)); $remainder = floor($datediff_days/(60*60*24)) - (floor($datediff_years/(60*60*24)) * 365); echo"$years years $remainder days)</td>"; echo"</tr>"; } mysql_free_result($get_oldest_player); // GET AVERAGE DOB OF STARTING XI $get_average_dob = mysql_query(" SELECT FROM_DAYS(AVG(TO_DAYS(P.PlayerDOB))) AS dob FROM tplss_players P, tplss_appearances A, tplss_matches M WHERE P.PlayerID = A.AppearancePlayerID AND A.AppearanceMatchID = M.MatchID AND M.MatchDateTime = '$matchdate' ",$connection) or die(mysql_error()); while($average = mysql_fetch_array($get_average_dob)) { echo"<tr>"; $dob = $average['dob']; $now = strtotime("$matchdate"); $your_date = strtotime("$dob"); $datediff_days = $now - $your_date; $datediff_years = $datediff_days / 365; $days = floor($datediff_days/(60*60*24)); $years = floor($datediff_years/(60*60*24)); $remainder = floor($datediff_days/(60*60*24)) - (floor($datediff_years/(60*60*24)) * 365); echo"<td width=30%>Average Player Age:</td><td width=70%>$years years $remainder days</td>"; echo"</tr>"; } mysql_free_result($get_average_dob); $get_players = mysql_query(" SELECT COUNT(P.PlayerID) AS players FROM tplss_players P, tplss_appearances A, tplss_matches M WHERE P.PlayerID = A.AppearancePlayerID AND A.AppearanceMatchID = M.MatchID AND M.MatchDateTime = '$matchdate' GROUP BY M.MatchID ",$connection) or die(mysql_error()); $get_scots = mysql_query(" SELECT COUNT(P.PlayerID) AS scots FROM tplss_players P, tplss_appearances A, tplss_matches M WHERE P.PlayerID = A.AppearancePlayerID AND A.AppearanceMatchID = M.MatchID AND M.MatchDateTime = '$matchdate' AND P.PlayerNationID = 1 GROUP BY M.MatchID ",$connection) or die(mysql_error()); while($players = mysql_fetch_array($get_players)) { echo"<tr>"; while($scots = mysql_fetch_array($get_scots)) { $average = ($scots['scots'] / $players['players']) * 100; $average = number_format((float)$average, 2, '.', ''); echo"<td width=30%>Domestic Players:</td><td width=70%>$scots[scots] ($average % of starting eleven)</td>"; } echo"</tr>"; } mysql_free_result($get_players); echo"</table>"; ?> <? // -----------SHOW FACTS ABOUT THE MATCHDAY SQUAD-------------- echo"<br> <h5>Matchday Squad</h5> <table width=100%> "; // GET YOUNGEST PLAYER IN SQUAD $get_youngest_player_all = mysql_query(" SELECT P.PlayerDOB AS dob, CONCAT(P.PlayerFirstName, ' ', P.PlayerLastName) AS name, P.PlayerID AS id FROM tplss_players P INNER JOIN ( SELECT AppearancePlayerID as PlayerID , AppearanceMatchID as MatchID FROM tplss_appearances UNION SELECT SubstitutePlayerID as PlayerID , SubstituteMatchID as MatchID FROM tplss_substitutes ) as total USING (PlayerID) INNER JOIN tplss_matches M USING (MatchID) WHERE M.MatchDateTime = '$matchdate' ORDER BY dob DESC LIMIT 0,1 ",$connection) or die(mysql_error()); while($youngest_all = mysql_fetch_array($get_youngest_player_all)) { echo"<tr>"; $dob = $youngest_all['dob']; echo"<td width=30%>Youngest Player:</td><td width=70%><a href=\"player.php?id=$youngest_all[id]\">$youngest_all[name]</a> ("; $now = strtotime("$matchdate"); $your_date = strtotime("$dob"); $datediff_days = $now - $your_date; $datediff_years = ($now - $your_date) / 365; $days = floor($datediff_days/(60*60*24)); $years = floor($datediff_years/(60*60*24)); $remainder = floor($datediff_days/(60*60*24)) - (floor($datediff_years/(60*60*24)) * 365); echo"$years years $remainder days)</td>"; echo"</tr>"; } // GET OLDEST PLAYER IN SQUAD $get_oldest_player_all = mysql_query(" SELECT P.PlayerDOB AS dob, CONCAT(P.PlayerFirstName, ' ', P.PlayerLastName) AS name, P.PlayerID AS id FROM tplss_players P INNER JOIN ( SELECT AppearancePlayerID as PlayerID , AppearanceMatchID as MatchID FROM tplss_appearances UNION SELECT SubstitutePlayerID as PlayerID , SubstituteMatchID as MatchID FROM tplss_substitutes ) as total USING (PlayerID) INNER JOIN tplss_matches M USING (MatchID) WHERE M.MatchDateTime = '$matchdate' ORDER BY dob ASC LIMIT 0,1 ",$connection) or die(mysql_error()); while($oldest_all = mysql_fetch_array($get_oldest_player_all)) { echo"<tr>"; $dob = $oldest_all['dob']; echo"<td width=30%>Oldest Player:</td><td width=70%><a href=\"player.php?id=$oldest_all[id]\">$oldest_all[name]</a> ("; $now = strtotime("$matchdate"); $your_date = strtotime("$dob"); $datediff_days = $now - $your_date; $datediff_years = ($now - $your_date) / 365; $days = floor($datediff_days/(60*60*24)); $years = floor($datediff_years/(60*60*24)); $remainder = floor($datediff_days/(60*60*24)) - (floor($datediff_years/(60*60*24)) * 365); echo"$years years $remainder days)</td>"; echo"</tr>"; } // GET AVERAGE DOB OF WHOLE SQUAD $get_average_dob_all = mysql_query(" SELECT FROM_DAYS(AVG(TO_DAYS(P.PlayerDOB))) AS dob FROM tplss_players P INNER JOIN ( SELECT AppearancePlayerID as PlayerID , AppearanceMatchID as MatchID FROM tplss_appearances UNION SELECT SubstitutePlayerID as PlayerID , SubstituteMatchID as MatchID FROM tplss_substitutes ) as total USING (PlayerID) INNER JOIN tplss_matches M USING (MatchID) WHERE M.MatchDateTime = '$matchdate' ",$connection) or die(mysql_error()); while($average_all = mysql_fetch_array($get_average_dob_all)) { echo"<tr>"; $dob = $average_all['dob']; $now = strtotime("$matchdate"); $your_date = strtotime("$dob"); $datediff_days = $now - $your_date; $datediff_years = ($now - $your_date) / 365; $days = floor($datediff_days/(60*60*24)); $years = floor($datediff_years/(60*60*24)); $remainder = floor($datediff_days/(60*60*24)) - (floor($datediff_years/(60*60*24)) * 365); echo"<td width=30%>Average Player Age:</td><td width=70%>$years years $remainder days</td>"; echo"</tr>"; } $get_players_all = mysql_query(" SELECT COUNT(P.PlayerID) AS allplayers FROM tplss_players P INNER JOIN ( SELECT AppearancePlayerID as PlayerID , AppearanceMatchID as MatchID FROM tplss_appearances UNION SELECT SubstitutePlayerID as PlayerID , SubstituteMatchID as MatchID FROM tplss_substitutes ) as total USING (PlayerID) INNER JOIN tplss_matches M USING (MatchID) WHERE M.MatchDateTime = '$matchdate' GROUP BY M.MatchID ",$connection) or die(mysql_error()); $get_scots_all = mysql_query(" SELECT COUNT(P.PlayerID) AS scots FROM tplss_players P INNER JOIN ( SELECT AppearancePlayerID as PlayerID , AppearanceMatchID as MatchID FROM tplss_appearances UNION SELECT SubstitutePlayerID as PlayerID , SubstituteMatchID as MatchID FROM tplss_substitutes ) as total USING (PlayerID) INNER JOIN tplss_matches M USING (MatchID) WHERE M.MatchDateTime = '$matchdate' AND P.PlayerNationID = 1 GROUP BY M.MatchID ",$connection) or die(mysql_error()); while($players_all = mysql_fetch_array($get_players_all)) { while($scots_all = mysql_fetch_array($get_scots_all)) { echo"<tr>"; $average = ($scots_all['scots'] / $players_all['allplayers']) * 100; $average = number_format((float)$average, 2, '.', ''); echo"<td width=30%>Domestic Players:</td><td width=70%>$scots_all[scots] ($average % of matchday squad)</td>"; echo"</tr>"; } } echo"</table>"; ?> <? //--------------CHECK FOR ANY DEBUTS---------------- // GET STARTING XI FOR DEBUTS $get_debuts = mysql_query(" SELECT CONCAT(P.PlayerFirstName, ' ', P.PlayerLastName) AS name, P.PlayerID AS id, DATE_FORMAT(P.PlayerSigned, '%M %D, %Y') AS signed FROM tplss_players P, tplss_appearances A WHERE A.AppearanceMatchID = '$id' AND P.PlayerID = A.AppearancePlayerID ORDER BY name",$connection); // GET SUBS FOR DEBUTS $get_sub_debuts = mysql_query(" SELECT CONCAT(P.PlayerFirstName, ' ', P.PlayerLastName) AS name, P.PlayerID AS id, DATE_FORMAT(P.PlayerSigned, '%M %D, %Y') AS signed FROM tplss_players P, tplss_substitutions S WHERE S.SubstitutionMatchID = '$id' AND P.PlayerID = S.SubstitutionPlayerIDIn ORDER BY name",$connection); echo"<br><h5>First Team Debuts</h5> <table width=100%>"; // SHOW ANY DEBUTS FOR PLAYERS IN STARTING XI while($appdata = mysql_fetch_array($get_debuts)) { $appplayerid = $appdata['id']; $get_starts = mysql_query(" SELECT COUNT(A.AppearancePlayerID) AS total FROM tplss_appearances A, tplss_matches M WHERE A.AppearancePlayerID = $appplayerid AND A.AppearanceMatchID = M.MatchID AND M.MatchDateTime <= '$matchdate' GROUP BY A.AppearancePlayerID ",$connection) or die(mysql_error()); $starts = mysql_fetch_array($get_starts); $get_subst = mysql_query(" SELECT COUNT(S.SubstitutionPlayerIDIn) AS total FROM tplss_substitutions S, tplss_matches M WHERE S.SubstitutionPlayerIDIn = $appplayerid AND S.SubstitutionMatchID = M.MatchID AND M.MatchDateTime <= '$matchdate' GROUP BY S.SubstitutionPlayerIDIn ",$connection) or die(mysql_error()); $subst = mysql_fetch_array($get_subst); $total_apps = $starts['total'] + $subst['total']; $head_url = "images/heads/" . $appplayerid . ".jpg"; if($total_apps == 1) { echo"<tr> <td width=20%> <img src=\""; if(file_exists($head_url)) { echo"images/heads/$appplayerid.jpg"; } else { echo"images/heads/none.jpg"; } echo"\" width=\"50\" style=\"border:0px solid; border-radius:25px;\"> </td> <td width=40%><a href=\"player.php?id=$appplayerid\">$appdata[name]</a></td><td width=40%>(Signed $appdata[signed])</td>"; } else { echo""; } } mysql_free_result($get_debuts); // SHOW ANY DEBUTS FOR PLAYERS COMING OFF BENCH while($appdatas = mysql_fetch_array($get_sub_debuts)) { $appplayerid = $appdatas['id']; $get_starts = mysql_query(" SELECT COUNT(A.AppearancePlayerID) AS total FROM tplss_appearances A, tplss_matches M WHERE A.AppearancePlayerID = $appplayerid AND A.AppearanceMatchID = M.MatchID AND M.MatchDateTime <= '$matchdate' GROUP BY A.AppearancePlayerID ",$connection) or die(mysql_error()); $starts = mysql_fetch_array($get_starts); $get_subst = mysql_query(" SELECT COUNT(S.SubstitutionPlayerIDIn) AS total FROM tplss_substitutions S, tplss_matches M WHERE S.SubstitutionPlayerIDIn = $appplayerid AND S.SubstitutionMatchID = M.MatchID AND M.MatchDateTime <= '$matchdate' GROUP BY S.SubstitutionPlayerIDIn ",$connection) or die(mysql_error()); $subst = mysql_fetch_array($get_subst); $total_apps = $starts['total'] + $subst['total']; $head_url = "images/heads/" . $appplayerid . ".jpg"; if($total_apps == 1) { echo"<tr> <td width=20%> <img src=\""; if(file_exists($head_url)) { echo"images/heads/$appplayerid.jpg"; } else { echo"images/heads/none.jpg"; } echo"\" width=\"50\" style=\"border:0px solid; border-radius:25px;\"> </td> <td width=40%><a href=\"player.php?id=$appplayerid\">$appdatas[name]</a></td><td width=40%>(Signed $appdatas[signed])</td>"; } else { echo""; } } mysql_free_result($get_sub_debuts); echo"</table>"; ?> <?php // --------------------CHECK FOR ANY MILESTONES---------------- // GET STARTING XI FOR MILESTONES $get_milestones = mysql_query(" SELECT CONCAT(P.PlayerFirstName, ' ', P.PlayerLastName) AS name, P.PlayerID AS id FROM tplss_players P, tplss_appearances A WHERE A.AppearanceMatchID = '$id' AND P.PlayerID = A.AppearancePlayerID ORDER BY name",$connection); // GET SUBS FOR MILESTONES $get_sub_milestones = mysql_query(" SELECT CONCAT(P.PlayerFirstName, ' ', P.PlayerLastName) AS name, P.PlayerID AS id FROM tplss_players P, tplss_substitutions S WHERE S.SubstitutionMatchID = '$id' AND P.PlayerID = S.SubstitutionPlayerIDIn ORDER BY name",$connection); // GET SCORERS FOR GOAL CHECKS $get_goals = mysql_query(" SELECT CONCAT(P.PlayerFirstName, ' ', P.PlayerLastName) AS name, P.PlayerID AS id FROM tplss_players P, tplss_goals G WHERE G.GoalMatchID = '$id' AND P.PlayerID = G.GoalPlayerID AND G.GoalOwn != 1 ORDER BY name",$connection); echo"<Br><h5>Milestones</h5> <table width=100%>"; // SHOW MILESTONES FOR STARTING XI while($appdatam = mysql_fetch_array($get_milestones)) { $appplayerid = $appdatam['id']; $get_starts = mysql_query(" SELECT COUNT(A.AppearancePlayerID) AS total FROM tplss_appearances A, tplss_matches M WHERE A.AppearancePlayerID = $appplayerid AND A.AppearanceMatchID = M.MatchID AND M.MatchDateTime <= '$matchdate' GROUP BY A.AppearancePlayerID ",$connection) or die(mysql_error()); $starts = mysql_fetch_array($get_starts); $get_subst = mysql_query(" SELECT COUNT(S.SubstitutionPlayerIDIn) AS total FROM tplss_substitutions S, tplss_matches M WHERE S.SubstitutionPlayerIDIn = $appplayerid AND S.SubstitutionMatchID = M.MatchID AND M.MatchDateTime <= '$matchdate' GROUP BY S.SubstitutionPlayerIDIn ",$connection) or die(mysql_error()); $subst = mysql_fetch_array($get_subst); $total_apps = $starts['total'] + $subst['total']; echo""; if($total_apps == '50') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$appdatam[name]</a> played his 50th major competitive game for the Club.</td></tr>"; } elseif($total_apps == '100') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$appdatam[name]</a> played his 100th major competitive game for the Club.</td></tr>"; } elseif($total_apps == '200') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$appdatam[name]</a> made his 200th competitive appearance for the Club.</td></tr>"; } elseif($total_apps == '250') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$appdatam[name]</a> played his 250th major competitive game for the Club.</td></tr>"; } elseif($total_apps == '300') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$appdatam[name]</a> made his 300th competitive appearance for the Club.</td></tr>"; } elseif($total_apps == '400') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$appdatam[name]</a> played his 400th major competitive game for the Club.</td></tr>"; } elseif($total_apps == '500') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$appdatam[name]</a> made his 500th competitive appearance for the Club.</td></tr>"; } else { echo""; } echo""; } mysql_free_result($get_milestones); // SHOW MILESTONES FOR SUBS while($appdatams = mysql_fetch_array($get_sub_milestones)) { $appplayerid = $appdatams['id']; $get_starts = mysql_query(" SELECT COUNT(A.AppearancePlayerID) AS total FROM tplss_appearances A, tplss_matches M WHERE A.AppearancePlayerID = $appplayerid AND A.AppearanceMatchID = M.MatchID AND M.MatchDateTime <= '$matchdate' GROUP BY A.AppearancePlayerID ",$connection) or die(mysql_error()); $starts = mysql_fetch_array($get_starts); $get_subst = mysql_query(" SELECT COUNT(S.SubstitutionPlayerIDIn) AS total FROM tplss_substitutions S, tplss_matches M WHERE S.SubstitutionPlayerIDIn = $appplayerid AND S.SubstitutionMatchID = M.MatchID AND M.MatchDateTime <= '$matchdate' GROUP BY S.SubstitutionPlayerIDIn ",$connection) or die(mysql_error()); $subst = mysql_fetch_array($get_subst); $total_apps = $starts['total'] + $subst['total']; if($total_apps == '50') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$appdatams[name]</a> played his 50th major competitive game for the Club.</td></tr>"; } elseif($total_apps == '100') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$appdatams[name]</a> played his 100th major competitive game for the Club.</td></tr>"; } elseif($total_apps == '200') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$appdatams[name]</a> made his 200th competitive appearance for the Club.</td></tr>"; } elseif($total_apps == '250') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$appdatams[name]</a> played his 250th major competitive game for the Club.</td></tr>"; } elseif($total_apps == '300') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$appdatams[name]</a> made his 300th competitive appearance for the Club.</td></tr>"; } elseif($total_apps == '400') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$appdatams[name]</a> played his 400th major competitive game for the Club.</td></tr>"; } elseif($total_apps == '500') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$appdatams[name]</a> made his 500th competitive appearance for the Club.</td></tr>"; } else { echo""; } } mysql_free_result($get_sub_milestones); // SHOW MILESTONES FOR STARTING XI while($goaldata = mysql_fetch_array($get_goals)) { $appplayerid = $goaldata['id']; $get_goal_totals = mysql_query(" SELECT COUNT(G.GoalPlayerID) AS total FROM tplss_goals G, tplss_matches M WHERE G.GoalPlayerID = $appplayerid AND G.GoalMatchID = M.MatchID AND M.MatchDateTime <= '$matchdate' GROUP BY G.GoalPlayerID ",$connection) or die(mysql_error()); $goals = mysql_fetch_array($get_goal_totals); $total_goals = $goals['total']; if($total_goals == '1') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$goaldata[name]</a> scored his first goal for the Club.</td></tr>"; } elseif($total_goals == '10') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$goaldata[name]</a> reached 10 goals for the Club.</td></tr>"; } elseif($total_goals == '25') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$goaldata[name]</a> scored for the 25th time for the Club.</td></tr>"; } elseif($total_goals == '30') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$goaldata[name]</a> reached 30 goals for the Club.</td></tr>"; } elseif($total_goals == '50') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$goaldata[name]</a> scored his 50th goal for the Club.</td></tr>"; } elseif($total_goals == '75') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$goaldata[name]</a> reached 75 goals for the Club.</td></tr>"; } elseif($total_goals == '100') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$goaldata[name]</a> scored his 100th goal for the Club.</td></tr>"; } elseif($total_goals == '200') { echo"<tr><td width=100%><a href=\"player.php?id=$appplayerid\">$goaldata[name]</a> scored his 200th goal for the Club.</td></tr>"; } else { echo""; } } echo"</table>"; mysql_free_result($get_goals); ?> <hr>Any suggestions or general advice would be greatly appreciated. I've been trying to figure out how chat apps work all afternoon to do dynamic data in HTML loading. Can someone please tell me where I'm going wrong for the code flow in this script:
<script> function submitchat{ if (form1.uname.value=='' || form1.msg.value==''){ alert("fill out whole form"); return; } var uname=form1.uname.value; var msg=form1.msg.value; var xmlhttp= new XMLHttpRequest(); xmlhttp.onreadystatechange = function(){ if (xmlhttp.readyState==4 && xmlhttp.status=200){ document.getElementById('chatlogs').innerHTML=xmlhttp.responseText; alert("message sent"); } xmlhttp.open('GET', '?page=3.2&uname='+uname+'&msg='+msg, true); xmlhttp.send(); } </script> <form name="form1"> enter your chat name<input type="text" name="uname"> message: <textarea name="msg"></textarea> <br> <div id="chatlogs">Loading Chat Logs...</div> <a href="#" onclick="">send</a> </form> <?php $uname = $_REQUEST['uname']; $msg = $_REQUEST['msg']; if ($msg!='' && $uname!=''){ $chat=" INSERT INTO chat ( `uname` , `msg` ) VALUES ( '$uname', '$msg' )"; $result = mysql_query($chat, $con) or die (sql_death($chat)); } I am trying to implement lazy loading into a project with pagination already set up.
If I was to go to my website and after the .com, type in "api_courselist.php?page=1" I would receive the first 20 results of my query. If I was to change that to page=2, it would retrieve the next 20 and so on.
My issue is I have no idea how to implement that into my java script/ajax file. I have it set up so that when the user scrolls to the bottom of the page, a div will make its self visible with the new page populated inside of it and IT will keep on pulling pages in till There is no more content.
jQuery(function ($) { jQuery(document).ready(function() { var is_loaded = true; jQuery(window).scroll(function() { if(jQuery(window).scrollTop() == jQuery(document).height() - jQuery(window).height()) { jQuery('div#loadMore').show(); if(is_loaded){ is_loaded = false; jQuery.ajax({ url: "api_courselist.php?page=1", success: function(html) { is_loaded = true; if(html){ jQuery("#infiscroll").append(html); jQuery('div#loadMore').hide(); }else{ jQuery('div#loadMore').replaceWith("<center><h1 style='color:red'>End of Content !!!!!!!</h1></center>"); } } }); } } }); }); }); I have below script. it does the while loop 100%. it updates the mysql database one at a time as it should. the problem I have now is that the while loop does not end and go to the next statement as it should. it keeps pollong the database. so when in back end you change to 0 it automatically updates again. Please see if you can help me to see where I can stop this while loop when there are no more loops // Here I select the amount of rows $sql_query = "SELECT ae FROM `debitorderrejectionimport` WHERE ae = '0'"; $rowCount = mysqli_query($conn,$sql_query); $rowCountUpdate = mysqli_num_rows($rowCount); echo $rowCountUpdate; while($rowCountUpdate > 0) { $sql = "UPDATE `ttee`.`au1` INNER JOIN `ttee`.`au` ON (`au1`.`id` = `au`.`id`) INNER JOIN `ttee`.`ae1` ON (`ae1`.`idd` = `au1`.`idd`) INNER JOIN `ttee`.`debitorderrejectionimport` ON (`debitorderrejectionimport`.`nr` = `ae1`.`id`) SET `au`.`amount` = `ae1`.`amount` + `au1`.`amount`, `debitorderrejectionimport`.`ae` = au.id ;"; $result = mysqli_query($conn, $sql); $updated = mysqli_affected_rows($conn); $rowCountUpdate - ($updated);} // if it finished updating and there is no more rows it must continue with below query mysqli_query($conn, " INSERT INTO `sataxicrm754`.`debitorderrejectionimport_back` ( `Outbound`, `Allocation`, `AccountName`, `QueryComplaintType`, `QueryStatus`, `Querytypeoption`, `Description`, `DealID`, `Deals`, `Assignedusername`, `Teams`, `CampaignName`, `CampaignID`, `inserted`, `idnumber`, `nr`, `datew`, `premium`, `policynumber`, `ContactNumber`, `CollectionType`, `OpportunityAmount`, `Broker`, `impref`, `id` ) SELECT `Outbound`, `Allocation`, `AccountName`, `QueryComplaintType`, `QueryStatus`, `Querytypeoption`, `Description`, `DealID`, `Deals`, `Assignedusername`, `Teams`, `CampaignName`, `CampaignID`, `inserted`, `idnumber`, `nr`, `datew`, `premium`, `policynumber`, `ContactNumber`, `CollectionType`, `OpportunityAmount`, `Broker`, `impref`, `id` FROM `sataxicrm754`.`debitorderrejectionimport` WHERE QueryComplaintType <> 'QueryComplaintType' ");
I have the following code that cycles though and prints out the day of the week and stops printing after the seventh day is reached, but it keeps looping. How do I stop it from looping after 7? I thought I had it right, but it's not. Can anyone help? Code: [Select] <?php $weekdays = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"); echo current($weekdays) . "<br />"; while (count($weekdays) < 8) { echo next($weekdays) . "<br />"; } ?> I'm writing PHP for my son's cub scout pack. It populates the MySQL db users table from data contained in a csv file. So far, it puts the scout's info in just fine...until I try to run another query as a nested query to retrieve the auto-generated userID for the scout that was just placed in the DB. The result of this if I don't include the second query--the one trying to get the new userID for that scout, it iterates through the whole file as expected and puts all the scouts in the users table. The second I uncomment the 2nd query and try to get it to run, it only puts the 1st scout in the DB, properly retrieves the newly generated userID for him, and then stops. I need to have this userID for the scout to properly associate that scout with the parents later on and in other sections of this project. the db_connect() function just creates the PDO object and contains the username, etc for the connection. That part is working fine so I'm not posting that function here. I've tried renaming the connection, query, etc to add "ID" to the end to ensure I wasn't trampling on var names, but that hasn't made a difference Code: [Select] //include necessary files: include_once("../../sys/php/includes/data_fns.php"); //start session session_start(); $conn = db_connect(); $bufferConn = $conn->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); //////////////////////////////////////// // Read through the .csv file and populate the users table /* Uses the model from the php documentation on fgetcsv: * $row = 1; if (($handle = fopen("test.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "<br />\n"; } } fclose($handle); } */ //////////////////////////////////////// $row = 0; //set the row counter $table1 = "<table id='csvTable'>"; //start the table HTML markup if(($handle= fopen("../../sys/source/pack238.csv", "r"))!== FALSE) //open the csv file { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) //fgetcsv reads through the csv file line by line { //ignore the first row which has the header data--we don't want that in the database if($row==0){$row++; continue;} $num = count($data); //get the scout's info, check to see if he's already in the db, then put it in if not--the scout should NOT already be in db when we run this for the first time, but later versions will only add new scouts. For now, just alert us if they're already in and halt //TODO Figure out why this still runs if the table name doesn't exist!! $query = "SELECT * FROM users WHERE fName=:firstName && lName=:lastName"; $stmt = $conn->prepare($query); $stmt->execute(array(':firstName'=>$data[1], ':lastName'=>$data[0])); $dbCount=0; while ($stmt->fetch()){$dbCount++;} if($dbCount >0) //we found this scout--he shouldn't be in the DB. Halt the process and check what's going on { echo "<br/>The scout, $data[1] $data[0] was found in the database already. We cannot continue. <b/>Please check this duplicate data and try running this setup again"; die(); } else //he's not in the DB....put him in there { //get the Den unit as a number, dropping "Den" $den = substr($data[10],4); //get birthday as something to be used as PHP date object if($data[7]!="") { $bdayO = date_create($data[7]); $now = date_create("now"); $interval = date_diff($bdayO, $now); $age = $interval->format('%y years'); $bday = $bdayO->format('Y-m-d'); } else{ $bdayO = NULL; $bday = NULL; $age = NULL; } echo "<br/> Test message: The scout $data[1] $data[0], Den:$den would be put into the database! His bday is:$bday. AGE IS: $age"; $query = "insert into users (gen,fName,lName, nName,memberOf,bday) VALUES ('M',:firstName,:lastName,:nickName,:den,:bday)"; $stmt= $conn->prepare($query); $stmt->execute(array(':firstName'=>$data[1], ':lastName'=>$data[0], ':nickName'=>$data[3], ':den'=>$den, ':bday'=>$bday)); //get the new userID for this scout now that he's in the db $connID = db_connect(); $queryID = "SELECT userID from users WHERE fName=:firstName && lName=:lastName"; $stmtID = $connID->prepare($queryID); $stmtID->execute(array(':firstName'=>$data[1], ':lastName'=>$data[0])); while ($row = $stmtID->fetch()) { $scoutUserID = $row[0]; echo "<br/>This scout's userID is: $scoutUserID"; } }//end else //get the father's info, check to see if he's already in the db, then put it in if not //if he is in the db, get this scout's userID number and add it to the father's children array $query = "SELECT * FROM users WHERE fName=:firstName && lName=:lastName"; $stmt = $conn->prepare($query); $stmt->execute(array(':firstName'=>$data[18], ':lastName'=>$data[19])); $dbCount=0; while ($stmt->fetch()){$dbCount++;} if($dbCount >0) //This father is already in the DB...we need to add this scout to his children array { echo "<br/>For testing purposes, this father is already in the DB...let's add this scout, ".$data[1]." to his children array"; //get the userID of the current scout } else //he's not in the DB....put him in there {} //get the mother's info, check to see if he's already in the db, then put it in if not //if she is in the db, get this scout's userID number and add it ot the mother's children array }// end while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) }//end if(($handle= fopen("../../sys/source/pack238.csv", "r"))!== FALSE) The code I am using designed to display the terms I am using in my search. For example: .php?description=red&purple&widgets displays red and purple widgets. However, I am also echoing the terms so people know what they are searching for: "Your are searching for red and purple widgets" However, by using the & sign it now displays "Your are searching for red" If I using .php?description=red%purple%widgets then nothing is displayed. Code: [Select] function sanitizeString($description) { $description = mysql_real_escape_string($description); $description = stripslashes($description); $description = htmlentities($description); return $var; I wrote a small application to force downloads of various large video files using readfile. This worked fine. However, the users have changed hosts and now it doesn't work. Small files are fine, but large files will cut off before finishing. Test file is 114MB, but it is always cut off at exactly 67.2MB or 51.4MB depending on a couple criteria. I've stripped the application down to the key part that's not working and run it on a test page the just immediately goes the file - no logins or any of that shenanigans and htaccess blocking either: $file = some/file/on/the/server.wmv; //114MB hea der('Content-Description: File Transfer'); hea der("Content-Type: application/octet-stream"); hea der("Content-Disposition: attachment; filename=" .basename($file)); hea der("Content-Transfer-Encoding: binary"); hea der('Expires: 0'); hea der('Cache-Control: must-revalidate, post-check=0, pre-check=0'); hea der('Pragma: public'); hea der('Accept-Ranges: bytes'); hea der("Content-Length: ".filesize($file)); ob_clean(); flush(); @readfile($file); (gaps in the header words are to prevent forum breakage) I've tried the following variations: transfer encoding - chunked (this results in getting a 51.4 MB download rather than 67.2) content-type application/force-download tried the default force-download code from the php.net manual tried the chunking function variations on php.net readfile page tried without accept ranges originally (only spotted that on this site) set_time_limt to one hour set max memory to 300MB (phpinfo has shown these changes did get accepted) used htacess to disable gzip and deflate (this results in getting a 51.4 MB download rather than 67.2) (SetEnv no-gzip dont-vary or RewriteEngine On RewriteRule . - [E=no-gzip:1] or RemoveOutputFilter DEFLATE html txt xml css js php wmv) None of these have solved the issue. The code worked fine on the old site, works fine on my site, and works fine on my test server. Direct downloads from the broken site also work fine, just not readfile downloads. The filesize is reading correctly if I echo just that, and it reads properly on the progress bar when downloading through readfile. The hosting company are blaming my coding. The htaccess is the bit I'm least sure of and I find it hard to get solid info on this part on the web. Is there anything wrong with my code that could be causing this? Am I missing something? What could be causing the problem? Many Thanks Hi all, I am managing a social network and am creating a script to allow the admin to private message all users on the site. Even setting the max execution time to unlimited within the file does not allow us to insert all 40,000 rows into the 'message' table, it stops after several thousand rows. Our hosts tell us setting this globally is a bad idea/unstable. Does anyone have some advice on the best to do this? No email notifications need to be sent so it is purely allowing the script to run it's full course without stopping. I did consider a cron job but without emails doing in 'batches' seems a bit unecessary so I'm clearly missing something. ANy and all advice would be most welcome! Richard how do i stop multiple duplications in database on my PHP script? ok i have attached a screenshot of what the database looks like after a few runs of my script. the script is designed to pull api information, input into 1 database and update another user table. i have made it run as a cron job every 60 minutes. here is my code: <?php /* You need multiple instances of this script. Each instance runs once every hour so 6 instances means one runs every 10 mins. Remember to change the API URL to reflect the different accounts or characters.*/ include "connect.php"; $columns = "`date` , `refID`, `refType`, `ownerName1`, `ownerName2`, `argName1`, `amount`, `balance`, `reason`"; //Live URL is //Assumeing that they are only donating at this time and no one is being paid to reduce the balance. Balance reduction can be done in the prize claim script so its not API delayed. if ( ($data[2] == "Player Donation") && ($data[4] == "Ship Lotto")){ $reUsed = mysql_query("SELECT * FROM bank WHERE refID='$data[1]';"); if(!empty($reUsed)){ $import="INSERT into bank($columns) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]')"; mysql_query($import) or die(mysql_error()); } /*check to see if the player has already been credited. It checks the last recorded reference # and checks to see if the new ref # is greater, else skips the processing. You need to check since the API gives you the last 1000 journal entries or 1 week, what ever is shorter. Not just what is new since last check. Check is performed by seeing if the record in the database for the user is less then or equal to the new once. This works only because CCP's reference #s are auto increasing so they only go up if they are newer, never down.*/ $name = $data[3]; //echo "Updating account of ".$name."<br />"; $queryLastRef = mysql_query("SELECT lastRef FROM users WHERE username='$name';") or die(mysql_error()); //echo $queryLastRef; $arraylastRef = mysql_fetch_assoc($queryLastRef); $lastRef = $arraylastRef["lastRef"]; //echo "The last reference # was: ".$lastRef."<br />"; $currentRef = $data[1]; //echo "The current reference # is: ".$currentRef."<br />"; if($lastRef<$currentRef){ $amount = $data[6]; //echo "Player deposited ISK in the amount of: ".$amount."<br />"; $queryBal = mysql_query("SELECT user_iskbalance FROM users WHERE username='$name';") or die(mysql_error()); //echo "Executing the SQL command to query balance ID#: ".$queryBal."<br />"; $getBal = mysql_fetch_assoc($queryBal); //echo "Executing the SQL command to get balance amount: ".$getBal["user_iskbalance"]."<br />"; $deposit = $amount+$getBal["user_iskbalance"]; //echo "Depositing ISK in the ammount of: ".$deposit."<br />"; $importBal= "UPDATE users SET user_iskbalance=$deposit WHERE username='$name';"; //echo "Executing the SQL command to desposit: ".$importBal."<br />"; mysql_query($importBal) or die(mysql_error()); $importRefID= "UPDATE users SET lastRef='$currentRef' WHERE username='$name';"; //echo "Executing the SQL command to set the new reference: ".$currentRef."<br />"; mysql_query($importRefID) or die(mysql_error()); //echo "Success!"."<br />"; //For the sake of stats tracking update the total isk on deposit. The payout script will subtract. $queryiskDeposit = mysql_query("SELECT iskDeposit FROM stats;") or die(mysql_error()); //echo "Executing the SQL command to query the ISK deposited : ".$queryiskDeposit."<br />"; $arrayiskDeposit = mysql_fetch_assoc($queryiskDeposit); $getiskDeposit = $arrayiskDeposit["iskDeposit"]; //echo "Got total isk on deposit of: ".$getiskDeposit."<br />"; $iskDeposit = $getiskDeposit+$deposit; //echo "Inserting: ".$iskDeposit." ISK"."<br />"; $importiskDeposit= "UPDATE stats SET iskDeposit='$iskDeposit';"; //echo "Executing the SQL command to desposit: ".$importBal."<br />"; mysql_query($importiskDeposit) or die(mysql_error()); //echo "<br />"; //echo "<br />"; //echo "NEXT!<br />"; //echo "<br />"; } else{ //echo "There is no update for ".$name." because ".$lastRef." is not less then or equal to ".$currentRef."<br />"; //echo "<br />"; //echo "<br />"; //echo "NEXT!<br />"; //echo "<br />"; } //echo "DEBUG for ".$name." lastRef ".$lastRef." and currentRef ".$currentRef."<br />"; //update the time that last update ran $today = date("Ymd G:i"); mysql_query("UPDATE stats SET iskLastUpdate='$today';") or die(mysql_error()); //echo "Updating Date to: ".$today; //echo "<br />"; //echo "<br />"; //echo "NEXT!<br />"; //echo "<br />"; } } ?> can anyone help me stop it duplicating the entries in the database please? I'm attempting to praise(if that's how you say it) txt data into xml with php and have come across a problem I've been unable to solve over the past two days so I'm coming here to ask the php gods for their assistance. The file I'm prasing contains line after line of real estate data. I understand what I'm doing I think. I've gotten the data in a format that is more usable, taking out the tabs and replacing them with spaces and such. I am creating a series of if than statements which will select the address out of each line even though each line can be different. At the end of the address on each line there is a "S" character which stands for some property I'm not concerned with. I'm simply using the single 'S' to find the end of the address. The lines look like so: \/ 403089 RESIDENTIAL Residential 385000 7610 N Lakeshore Dr. Harbor Springs S 3 2 0 None 3 Litzenburger, Boo Schaffer Real Estate 399562 RESIDENTIAL Condominium 155000 4749 Pleasantview Road Harbor Springs S 2 2 0 One Hartwick, Bob Coldwell Banker Schmidt With a bunch of extra text following that I've trimmed off for our purposes here. See the 'S' after the town? I've created the following code to look for the 's' in relation to the word order. Code: [Select] <?php // Listings file $listings= file('listingsTest.txt'); $i = 0; $j = 0; $_ENV['a'] = 0; foreach($listings as $value) { //Replace all spaces of every kinds with single spaces $listings[$i] = preg_replace("'\s+'", ' ', $listings[$i]); //Put all characters into an array corisopndings to each line in $listings $_ENV['chars'.$i] = preg_split('//', $listings[$i]); //Place all words and uninterupted numbers and place in array $words $_ENV['words'.$i] = preg_split('/ /', $listings[$i]); $i++; } //echo $_ENV['chars'.'1']['1']; foreach($_ENV['words'.$_ENV['a']] as $char){ $countedf = preg_split('//', $_ENV['words'.$_ENV['a']][$j]); $counted = count($countedf) - 2; $wordBeforef = preg_split('//', $_ENV['words'.$_ENV['a']][$j-1]); $wordBefore = count($wordBeforef) - 2; $wordAfterf = preg_split('//', $_ENV['words'.$_ENV['a']][$j+1]); $wordAfter = count($wordAfterf) - 2; if( ($counted == 1) && ($wordAfter == 1) && (is_numeric($_ENV['words'.$_ENV['a']][$j+1])) //&& ($wordBefore == 1) //&& (!is_numeric($_ENV['words'.$_ENV['a']][$j])) //&& (is_numeric($_ENV['words'.$_ENV['a']][$j+2])) //&& ($_ENV['words'.$_ENV['a']][$j+3] == ' ' ) ){ echo '*'; echo $_ENV['words'.$_ENV['a']][$j]; echo '*'; $_ENV['a']++; $j =0; //$j=1 } //echo $_ENV['chars'.$_ENV['a']][$j]; $j++; } ?> As you can see from the if then statements, I've gotten to the point where It's replying to the 'S' at the end of the address thus telling me where the address ends. I am however having a problem I believe is a server issue. The code works fine when applied to 12 lines like the ones above, when I apply it to more of those lines it does not return the 'S' for them even if I used the exact same line more than 12 times. The main file which I'd like to automate the parsing of has thousands of these such lines in it. If I try to apply this code to the file with these thousands of lines, the browser returns a "The website encountered an error while retrieving http://localhost. It may be down for maintenance or configured incorrectly". I take this to mean the server is doing too much work for it to be completed. I think when it reaches it's twelfth, the temporary memory of my program/server or some thing else, is exhausted. I'm applying these if then statements to every single word in the file. Is this a processing issue on the server? I was applying this code to every character in the file and thought I could fix the problem by applying instead to every word given there are less words than characters. I have the processing time on the server set to 10000 and it's not taking along time to return the error message. I would be very grateful to any help any of you could provide. Thank you for your time. |