-
Posts
16,734 -
Joined
-
Last visited
-
Days Won
9
Everything posted by PFMaBiSmAd
-
It would probably be best if you posted the original script, without any of the pagination logic.
-
Pagination requires that you form two similar queries. The first one to get a count (usually with a SELECT COUNT(*) term) of the rows that match the WHERE clause you are using (which is not necessarily all the rows in your table), the second one with a LIMIT clause added on the end of the query to get the correct set of rows for the requested page. In order for your code to accomplish this, you will need to start by building the desired query in a php variable, rather than forming the query inside of the msyql_query() statement. Once you have the base query built with the desired WHERE clause, you can then use that query in the pagination logic.
-
are there any differences between PHP Version 5.2.9 and 5.2.14 ?
PFMaBiSmAd replied to jasonc's topic in PHP Coding Help
jasonc, nothing you wrote in your last reply has anything to do with what was suggested to do or try or tell us to help find what your code is currently doing in order to find where the problem is. You didn't even read your page is being requested twice, the first time the reset code matches an entry in the database, .... It's your resetpw2.php page that gets requested with the reset code. -
are there any differences between PHP Version 5.2.9 and 5.2.14 ?
PFMaBiSmAd replied to jasonc's topic in PHP Coding Help
A) Get rid of all the @ error suppressors in your code. There's no reason to ever put them into code and they could be hiding the reason why your code is not doing what you expect (they also minutely slow down your code just by having them present, even when there are no errors being suppressed.) You should have display_errors set to OFF for a live server (set it to ON for debugging purposes.) Your web host should have it set to OFF in the master php.ini, but if he doesn't, you can set it the way you want it to be (off most of the time, on for debugging) in a local php.ini (when php is running as an CGI application), in a .htaccess file (when php is running as an Apache Module), or in your script, such as in a common config.php file that you include into each page. B) You are not testing if the queries worked or failed with an error before you attempt to access any of the data from the queries (which I suspect is why you have @'s on things like the mysql_num_rows and mysql_result statements.) C) Are you sure the random reset code is being saved/updated in the database at all and that it is the exact same value as what is being put into the link? D) As already mentioned, the symptom is starting to suggest that your page is being requested twice, the first time the reset code matches an entry in the database, for the second request, the entry does not exist. Are you actually receiving the email with the new random password? -
are there any differences between PHP Version 5.2.9 and 5.2.14 ?
PFMaBiSmAd replied to jasonc's topic in PHP Coding Help
I was hoping that would show us what the actual output was from your script so that it would indicate what execution path was being taken and/or if there is more than one request for the page. -
are there any differences between PHP Version 5.2.9 and 5.2.14 ?
PFMaBiSmAd replied to jasonc's topic in PHP Coding Help
What does a 'view source' in your browser of the page show? -
PHP formmailer doesn't work on different computers
PFMaBiSmAd replied to jewelsmac6's topic in PHP Coding Help
Internally the script is using the phpmailer class and the only way that the redirect to the thank-you.php will occur is if the mailer->Send() method returns a true. That implies that there is a sending mail server, the php script was able to connect to it, and it accepted the mail to send without returning any errors. That would suggest that something that is submitted in the fields or as the file attachment is causing the problem, either on the sending mail server or at the receiving mail server. When you try this on the different computers, are you entering the same exact information in the form fields and using the same file attachment? Is your sales@dependableprint.com email address hosted on the same mail server as where the web page/this php script is running, i.e. is the sending mail server (at your web host) the same as the receiving mail server? -
You are missing an S on one of the $_FILES
-
Probably a folder or a permission problem. Add the following two lines of code immediately after your <?php tag to get php to report and display any errors it detects - ini_set("display_errors", "1"); error_reporting(-1);
-
PHP formmailer doesn't work on different computers
PFMaBiSmAd replied to jewelsmac6's topic in PHP Coding Help
Any symptoms or errors when you try this? Does the page redirect to the thank-you.php page? Does the form just refresh? -
-
There's no reason for the table to have any rows, except those that have miss, hit, or win data. To reset, you simply drop/recreate an empty table or truncate the existing table.
-
Suggestion: Good Guys / Bad Guys
PFMaBiSmAd replied to Jumpy09's topic in PHPFreaks.com Website Feedback
The problem with both positive and negative opinions/reviews posted on the Internet, is that ANYONE (even the person being reviewed) can easily get any number of identities and become an author and write posts. I can just about guarantee that a majority of the positive reviews, posted soon after the original entry is created, are written not by someone who was a satisfied customer, but by the originator to add to his apparent reputation Then there would be the negative reviews, either real, perceived, or made up, that result in a stream of replies between the originator and the dissatisfied customer, trying to use the forum argue a dispute in public that belongs in private between them and/or their lawyers and/or in a small claims court system. Both positive and negative replies would require verification that the person making the reply was actually someone who had work done by the originator. I recommend the BBB (Better Business Bureau) for this type of thing, not a programming forum that happens to have a freelancing board. -
What exactly have you done to troubleshoot the problem? Is the link being produced correctly with the correct id value? If so, then the only relevant code would be the code that is executed when the link is clicked and operates on the get parameter from the link. Posting hundreds of lines of code that isn't even relevant to the problem isn't going to get many replies. Also, you posted the code using the bbcode tags. That messes up the white-space in the code (every tab gets a new-line added to it, resulting in multi-hundreds of lines of code), so no one will likely copy/paste it to even search through it to try and find the relevant code. Use the bbcode tags when posting code.
-
Assuming that you want all references to the language file to occur through that function, you should probably use a class, but you could (probably, this is untested) do this using a function and a static variable to prevent the code from including the language file every time the function is called. On the first call to the function, you would detect that the static variable holding the $lang array has not been initialized and then validate the $_GET (the $_GET array is a super global and is automatically available inside of functions) variable and include the correct language file, assigning the $lang array to the function's statically defined variable.
-
A dynamically produced GIF image, to replace the grid of images, using GD functions, with mostly the background image (g.gif) and one each of the other three images (b.gif - miss, h.gif - hit, chest.gif - win) results in a ~72KB image. Sample code - <?php $x = 34; // grid size $y = 32; // grid size $img_x = 16; // tile/image size $img_y = 16; // tile/image size $width = $x * $img_x; $height = $y * $img_y; if(isset($_GET['img'])){ // some test data - $data[5] = array('clicked'=>1); $data[6] = array('clicked'=>2); $data[7] = array('clicked'=>3); $bg_name = "g.gif"; $miss_name = "b.gif"; $hit_name = "h.gif"; $win_name = "chest.gif"; $im = imagecreatetruecolor($width,$height); // canvas $bg = imagecreatefromgif($bg_name); // background $miss = imagecreatefromgif($miss_name); $hit = imagecreatefromgif($hit_name); $win = imagecreatefromgif($win_name); $c = 0; $dst_x = 0; $dst_y = 0; for($i=1; $i<=$y; $i=$i+1){ for($j=1; $j<=$x; $j=$j+1){ $c++; $clicked = 0; // default value if(isset($data[$c])){ $clicked = $data[$c]['clicked']; } if ($clicked == "1"){ //echo "<img src='b.gif' alt=''>"; // miss imagecopy($im, $miss, $dst_x , $dst_y ,0,0,$img_x,$img_y); }elseif ($clicked == "2"){ //echo "<img src='h.gif' alt=''>"; // hit imagecopy($im, $hit, $dst_x , $dst_y ,0,0,$img_x,$img_y); }elseif ($clicked == "3"){ //echo "<img src='chest.gif' alt=''>>"; // win imagecopy($im, $win, $dst_x , $dst_y ,0,0,$img_x,$img_y); }else{ // some other value or doesn't exist in the database table //echo "<img src='g.gif' alt=''>"; // background imagecopy($im, $bg, $dst_x , $dst_y ,0,0,$img_x,$img_y); } $dst_x += $img_x; // next column } $dst_x = 0; // reset $dst_y += $img_y; // next row } header("Content-type: image/gif"); imagegif($im); } else { echo "<img src='?img' alt='' width='$width' height='$height'>"; }
-
There's only a http request for each different image on the page.
-
Does your table contain all 1088 rows, even if those rows don't actually contain any data? A typical game will use a minority of the positions on the grid. You should only store rows that have been clicked (miss, hit, won.)
-
<?php $query = "SELECT * FROM grid ORDER BY `ID`"; $data=array(); $result = mysql_query($query); while($row=mysql_fetch_assoc($result)){ $data[$row['ID']] = $row; } echo "<table width='20' border='0' cellspacing='0' cellpadding='0'>"; $c = 0; for($i=1; $i<=32; $i=$i+1){ echo "<tr>"; for($j=1; $j<=34; $j=$j+1){ $c++; $clicked = 0; // default value if(isset($data[$c])){ $clicked = $data[$c]['clicked']; $hitby = $data[$c]['user']; } if ($clicked == "1"){ echo "<td title='$j, $i'><img src='b.gif' alt=''></td>"; }elseif ($clicked == "2"){ //if the ship was hit echo "<td title='$j, $i - Hit by $hitby.'><img src='h.gif' alt=''></td>"; }elseif ($clicked == "3"){ //if is chest echo "<td title='$j, $i - $prevamount btc won by $hitby.'><img src='chest.gif' alt=''></td>"; }else{ // some other value or doesn't exist in the database table echo "<td><a href='index.php?c=$c'><img src='g.gif' alt=''></a></td>"; } } echo "</tr>\n"; } echo "</table>";
-
Using === for the comparison operator should work.
-
Yes, you use one query to retrieve all the data you want in the order that you want it. Then simply and quickly iterate over that data and display it the way you want.
-
Does that mean that was a unneeded query, that you removed it, and that this thread is solved?
-
I need help to optimize my MySQL queries, it takes forever to load
PFMaBiSmAd replied to tjc19999's topic in PHP Coding Help
Based on the assumptions, the following should be in the ballpark of how you could do this with a minimum of queries, no queries inside of a loop (actual queries untested of course) - <?php $today = date("Y-m-d"); $lastmonth = date("Y-m-d", mktime(0,0,0,date("m")-1 , date("d"), date("Y"))); $twoweeks = date("Y-m-d", mktime(0,0,0,date("m") , date("d")-14, date("Y"))); $urlarray = array(); // get a list of all urls (I'm guessing your $urlarray code is similar to this.) $query = "SELECT DISTINCT refer FROM `approved` ORDER BY refer"; // you may want to limit this to some past date (a few months ago) so that you only get current urls $result = mysql_query($query); while($row = mysql_fetch_assoc($result)){ $urlarray[] = $row['refer']; } $counts = array(); // get the last month counts $query = "SELECT refer,Count(*) as count FROM `approved` WHERE DATE(time) >= '$lastmonth' GROUP BY refer"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)){ $counts[$row['refer']]['lastmonth'] = $row['count']; } // get the last twoweek counts $query = "SELECT refer,Count(*) as count FROM `approved` WHERE DATE(time) >= '$twoweeks' GROUP BY refer"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)){ $counts[$row['refer']]['last2weeks'] = $row['count']; } $data = array(); // get the data $query = "SELECT refer,COUNT(*) AS count,DATE(time) as date FROM `approved` WHERE DATE(time) >= '$lastmonth' GROUP BY refer, DATE(time)"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)){ $data[$row['refer']][$row['date']] = $row['count']; } // build a list of dates (used for headings and referencing data) $dates = array(); $curdate = $lastmonth; // starting value while($curdate <= $today){ $dates[] = $curdate; $curdate = date('Y-m-d',strtotime("$curdate + 1 day")); } // output table and heading row echo '<table><tr><th>Domain</th><th>Last<br />Mo</th><th>Last<br />2Wk</th>'; foreach($dates as $date){ echo "<th>". substr($date,0,4) . "<br />" . substr($date,5,5)."</th>"; // YYYY over MM-DD } echo "</tr>\n"; $i = 0; // loop over all the urls foreach($urlarray as $url){ if(!isset($counts[$url]['lastmonth'])){ // no records for this url during the range of dates $counts[$url]['lastmonth'] = 0; } if(!isset($counts[$url]['last2weeks'])){ // no records for this url during the range of dates $counts[$url]['last2weeks'] = 0; } if($counts[$url]['lastmonth']==0){ echo "<tr style='background:red'>"; // lastmonth count == 0 }elseif($counts[$url]['last2weeks']>0){ echo "<tr style='background:green'>"; // lastmonth != 0 and twoweek count > 0 }elseif($i % 2){ echo "<tr style='background:#CCC'>"; // lastmonth != 0 and twoweek count == 0, alternate bg color }else{ echo "<tr style='background:#FFF'>"; // lastmonth != 0 and twoweek count == 0, alternate bg color } echo "<td>$url</td><td>".$counts[$url]['lastmonth']."</td><td>".$counts[$url]['last2weeks']."</td>"; // loop over each day foreach($dates as $day){ if(isset($data[$url][$day])){ echo "<td>".$data[$url][$day]."</td>"; } else { echo '<td>0</td>'; // no records for this url for this day } } echo "</tr>\n"; $i++; } echo '</table>'; ?> -
I need help to optimize my MySQL queries, it takes forever to load
PFMaBiSmAd replied to tjc19999's topic in PHP Coding Help
I just realized, after going through what the code is trying to produce, that you probably have specific values in the $timearray. It is a list of specific YYYY-MM-DD dates?