Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. Cannot really help you without seeing the exact whole file that you tried to run.
  2. This topic has been moved to MySQL Help. http://forums.phpfreaks.com/index.php?topic=363233.0
  3. Column names are not enclosed within single-quotes. SUBSTRING_INDEX('last_post', '|', 1) is trying to find the | character within the literal string last_post
  4. Try this - // detect direct access to included/required file if(strtolower(basename($_SERVER["SCRIPT_NAME"])) == strtolower(basename(__FILE__))){ exit('No Direct Access'); }
  5. The PHP version test and error message has nothing to do with the code you have posted. How about giving us the name of this script and posting a link to the Author's site?
  6. A) What does your question have to do with the mysql help section where you posted this? B) Lower than 5.0.0 means 4.x. If you are using a script that still requires php4, you have got to ask yourself why, because the end of life of php4 was in 2007, with the last security update in 2008. C) There are actually very few incompatible changes going from php4 to php5 (most problems are due to relying on deprecated php,ini settings) and the script will likely work, if you disable the version checking in it.
  7. Your code in index.php would take the requested date made up from the day1, month1, and year1 get parameters, determine if that date it is a weekday or weekend day, and output the correct booking table. strtotime and date can be used together to get the day of week numerical or textual representation for the date.
  8. I merged your threads for this together. If you already have an existing thread for a problem, don't start another thread for the same problem, especially if someone went to the trouble of reading your existing thread and asked a question about it in order to try and help.
  9. Here's an example search/pagination script - <?php // settings used by this code - $rows_per_page = 20; // how many rows to display per logical page $pagination_name = 'pageno'; // the $_GET[xxxxx] index name to use for pagination $pagination_range = 3; // maximum number of pagination links to show either side of the currently selected page // connect to your database server and select your database here... // assuming this is being used for a search script, output a simple search form and produce a $where_clause to match the rows you are interested in $search_form = "<form method='get' action=''>Search: <input type='text' name='search'><input type='submit'></form>"; echo $search_form; // get and condition any search term $search = isset($_GET['search']) ? trim($_GET['search']) : ''; $where_clause = ''; if($search != ''){ // form a simple LIKE '%serach term%' comparison $where_clause = sprintf("WHERE your_column LIKE '%%%s%%'",mysql_real_escape_string($search)); } // define the main and count queries $main_query = "SELECT * FROM your_table $where_clause"; $count_query = "SELECT COUNT(*) FROM your_table $where_clause"; // find the total number of matching rows $result = mysql_query($count_query) or die("Query failed: $count_query<br />Error: " . mysql_error()); list($total_rows) = mysql_fetch_row($result); // calculate the total number of logical pages $total_pages = ceil($total_rows/$rows_per_page); // get and condition or set a default for the requested page $requested_page = isset($_GET[$pagination_name]) ? intval($_GET[$pagination_name]) : 1; // set max/min limits for the requested page. max first, then min so if the total is zero (no matching data), the requested page is 1 if($requested_page > $total_pages){ $requested_page = $total_pages; } if($requested_page < 1){ $requested_page = 1; } // calculate the starting row number for the requested logical page $offset = ($requested_page - 1) * $rows_per_page; // form the actual query to retrieve the matching data for the requested logical page $query = "$main_query LIMIT $offset, $rows_per_page"; // query for the actual data $result = mysql_query($query) or die("Query failed: $query<br />Error: " . mysql_error()); // get number of rows returned by the query for the logical page $num_rows = mysql_num_rows($result); if($num_rows == 0){ // query matched no rows echo "There are no matching records to display on this page."; } else { echo "Your query matched $total_rows record" .($total_rows > 1 ? 's' : '').". "; echo "Displaying records: ".($offset+1)." - " . ($offset+$num_rows) . ".<br />"; // loop over the matching rows and output the data the way you want on your page while($row = mysql_fetch_assoc($result)){ echo $row['your_column'] . '<br />'; } } // build pagination navigation links (if there's more than one page) // this code uses http_build_query to build the query string on the end of the URL so that any existing get parameters, such as a search term, are not modified. This code only modifies the pagination get parameter and leaves all other get parameters as is. $pagination_links = ''; // build pagination links in a string (output it later in your actual content on the page) if($total_pages > 1){ // produce 'first' and 'prev' links if($requested_page > 1){ // 'first' page link $_GET[$pagination_name] = 1; // set/replace the pagination GET parameter (all other GET parameters unchanged) $pagination_links .= "<a href='?" . http_build_query($_GET, '', '&') . "'><<</a> "; // 'prev' page link $_GET[$pagination_name] = $requested_page - 1; // set/replace the pagination GET parameter (all other GET parameters unchanged) $pagination_links .= " <a href='?" . http_build_query($_GET, '', '&') . "'><</a> "; } else { // text only place holders $pagination_links .= " << < "; } // loop to produce links for a range of pages around the currently selected page for($x = $requested_page - $pagination_range; $x < $requested_page + $pagination_range + 1; $x++){ // if between min and max page number if($x > 0 && $x <= $total_pages){ // if currently requested page, output text only place holder if($x == $requested_page){ $pagination_links .= " [<b>$x</b>] "; } else { // output page link $_GET[$pagination_name] = $x; // set/replace the pagination GET parameter (all other GET parameters unchanged) $pagination_links .= " <a href='?" . http_build_query($_GET, '', '&') . "'>$x</a> "; } } } // produce 'next' and 'last' links if($requested_page != $total_pages){ // 'next' page link $_GET[$pagination_name] = $requested_page + 1; // set/replace the pagination GET parameter (all other GET parameters unchanged) $pagination_links .= " <a href='?" . http_build_query($_GET, '', '&') . "'>></a> "; // 'last' page link $_GET[$pagination_name] = $total_pages; // set/replace the pagination GET parameter (all other GET parameters unchanged) $pagination_links .= " <a href='?" . http_build_query($_GET, '', '&') . "'>>></a>"; } else { // text only place holders $pagination_links .= " > >>"; } } // output the pagination navigation links echo $pagination_links; // echo the links wherever you want in the content on your page
  10. See items #2 and #3 in the following post - http://forums.phpfreaks.com/index.php?topic=363037.msg1717726#msg1717726
  11. I would just use array_map to apply your function to all elements of the $_POST array - $arr = array_map('fromuser',$_POST); Use $arr['first_name'], $arr['last_name'], ...
  12. Output_buffering is turned on in your php.ini. You either need to turn it off, or insure you don't output anything before the actual data, or you can use ob_end_clean right before you output your actual data.
  13. No php script is needed, you can calculate an average directly in a query - http://dev.mysql.com/doc/refman/5.5/en/group-by-functions.html#function_avg
  14. This topic has been moved to PHP Freelancing. http://forums.phpfreaks.com/index.php?topic=363088.0
  15. The IN() comparison will match the row(s) where the comparison is TRUE. WHERE playerid IN(1,1) is the same as WHERE playerid = 1 OR playerid = 1 and it only returns the one single row with playerid = 1.
  16. Your code inside of the various loops is reusing and overwriting the $result variable, so after the first pass through the outer loop, $result no longer contains the result resource/object for that loop.
  17. If $_POST['players'] is the array that you indicated in the first post, that would work. Have you confirmed what $_POST['players'] actually contains? Is this code inside your form processing code that has detected that the form has been submitted?
  18. You need to test the ['error'] element - http://us2.php.net/manual/en/features.file-upload.errors.php If($_FILES['file']['error'] === 0){ // test for exactly === a zero value // the file uploaded successfully and you can access the ['name'], ['type'], ['size'], and ['tmp_name'] elements }
  19. Since $title and $content don't exist in the code you are using, there's no way that the query will match any rows in your database table. What exactly are you trying to achieve by that query statement and where are you expecting $title and $content to be set from?
  20. You would implode the array to make a comma separated list and use the mysql IN() comparison in the WHERE clause - http://dev.mysql.com/doc/refman/5.5/en/comparison-operators.html#function_in
  21. 1) The WHERE clause you are building and putting into the second query, must also be put into the first (COUNT()) query so that the $total_pages calculation will be correct for the number of records that match that WHERE clause. 2) You must carry the $_POST['searchterm'] value as a $_GET parameter in the url so that it will be present on each page request. Changing your search form to use method='get' would be acceptable since you are specifying what the page should output as the result of a request. 3) The pagination links that you produce must carry any existing $_GET parameters and just set the $_GET['page'] value. See the following post for how you can produce the pagination links so that they only set the $_GET parameter used for pagination and leave all other $_GET parameters as is - http://forums.phpfreaks.com/index.php?topic=348834.msg1646676#msg1646676
  22. That's backwards. Cutting off a foot(er), without adequate medical attention, usually results in dieing. Hay, what did you expect. Telling your code to die is an immediate and terminal condition (there's no php CPR statement.)
  23. Some suggestions - 1) You need to remove the @ error suppressors from your code. They minutely slow down the execution, simply by being present, because every time they are encountered, php saves the current error_reporting level, sets the error reporting level to zero, executes the statement the @ applies to, then restores the previous error_reporting level and if the statement actually does produce a php error, the error must still be detected and the php error handler is still called (the reporting and display/logging of errors is just the final step in the error handling code.) 2) Your code should be structured to first determine what permissions the current visitor has on any page request, then get and produce JUST the output that is available for the current visitor. The code currently appears to be executing queries inside of loops inside of other query/loops, three or four levels deep, looping through every item and checking the permissions of each.
  24. Did you remove the or die() after all the mysql_fetch_assoc statements? If there are no rows in a result set, the mysql_fetch_assoc statement returns a false value which causes the or die() statement to be executed. But because this isn't a mysql error, the mysql_error() output is empty and your page dies at that point with no output.
  25. This topic has been moved to Miscellaneous. http://forums.phpfreaks.com/index.php?topic=362976.0
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.