Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. You would use a database table that associates the user_id with the content_id that he can access (one row for each user_id/content_id association.) You would JOIN this table with the table holding the content to limit the content that the query returns to the specific user_id. The following assumes your login system stores the current user's id in $_SESSION['user_id']. // a query that gets all the content that the current visitor can access - $query = "SELECT c.id,c.title,c.content FROM content c JOIN access_table a ON c.id = a.content_id AND a.user_id = {$_SESSION['user_id']}"; // a query that gets one specific row (the id of the content is in $id) that the current visitor can access - $query = "SELECT c.id,c.title,c.content FROM content c JOIN access_table a ON c.id = a.content_id AND a.user_id = {$_SESSION['user_id']} AND c.id = $id";
  2. The php datetime class/extension should not have this problem, even on 32bit systems, assuming that you don't try to convert the result to a Unix timestamp in an integer variable.
  3. Also, this is a continuation of a existing thread (where you do provide some small information about what you are trying to do.) Two topics merged... Finally, the mysql extension is being discouraged for new code. php.net suggests using the mysqli extension.
  4. You also should NOT be executing queries inside of loops. If you post your table definition and some sample data and what result you are tying to achieve for that data, someone can point you in the proper direction (i.e. the implication of what you are doing indicates an improper table design.)
  5. On 32bit versions of php, the maximum integer value corresponds to - Tue, 19 Jan 2038 03:14:07 UTC
  6. Also, you should NOT be repeatedly creating a database connection and then closing it inside of a loop. Your application should create a database connection once and let php close it when the code on the page ends.
  7. array_diff_assoc will give you keys/values that are different between an original data array and the submitted data from the form.
  8. Post the exact .php script you used with the phpinfo statement in it, showing the opening php tag you used.
  9. So, it sounds like your callsign value is being used to determine what happens in your code, rather than being used in a database query? In which case using any mysql_ function on the data won't actually prevent anything. P.S. Your code attachment didn't actually work in your post above. You should actually post your code in the thread as most people won't visit links or download files found in posts.
  10. The read/unread status only applies to the recipient. You would only use it for highlighting when the current user is the recipient, not when the current user is the sender. The messages in any user's 'in box' are when the current user = recipient. The messages in any user's 'out box' are when the user = sender. Messages someone sends aren't in their inbox.
  11. This is a lot of work to execute a query to get product details, which btw should not be inside of a loop. For your existing code, the ->prepare() and ->bind_parm() statements should be before the start of your loop. You should actually be executing the query once, before the start of your loop, with a where clause - WHERE id IN(?,?,? - repeat for the number of id's...), then just loop over the result set from that one query. Using prepared statements, this will require that you dynamically build the ->bind_parm parameters in an array and use call_user_func_array()
  12. See the following post on pagination, using http_build_query, to make the links with any GET parameters that your code might already have along with the ones for pagination - http://forums.phpfreaks.com/topic/268497-pagination/page__hl__+http_build_query#entry1378864
  13. No one here can really tell you what application will fit your needs, without knowing exactly what your needs are (kind of like asking someone else what car make/model is easy to drive, but it turns out you needed a school bus.) Here's a site with demos of the popular opensource php applications for you to examine - http://www.opensourcecms.com/
  14. Your code that is setting $_SESSION['invoice'][$comic_id] is outside of and after the end of your loop. You would need to put in with the code that is fetching the data from the query result and setting the $name, $qty, and $price variables.
  15. Pika's reply contains a link to the mysql documentation for that function. There's an example at that link.
  16. Your database table that you are using to store the 'online' user information, needs to store the 'last access time' for each user. Then, when you are displaying the 'online' list, you only retrieve the records where the 'last access time' is within x seconds of the current time. Or you can just delete the records where the 'last access time' is older than x seconds from the current time and display the remaining records.
  17. You have a spelling error in your session variable. It's - $_SESSION Do you have php's error_reporting set to E_ALL and display_errors set to ON in your master php.ini so that php will help you by reporting and displaying all the errors it detects. You will save a TON of time. Your second test, with two conditions, would need to use an and comparison operator &&
  18. So, is the exact format you are trying to test for a '#', followed by two upper-case letters, followed by three numerical characters?
  19. If your promotional code must be one from an exact list, you would store that list in a database and check if the entered value was in the database. If your promotional code must only match a specific format, you would test in your php code for that format. Since you haven't stated exactly what the limits/rules are for what you are trying to do, we don't have enough information to help you.
  20. Here's an example where using extract on a database query result would open a security hole. What if you have a database table search form on your page that is open to sql injection (it's only selecting data from your product/blog/news table after all, how dangerous could that be to your code?) By injecting SELECT ... 'value' AS some_variable_name ... the extract() statement would cause php to do this - $some_variable_name = 'value'; This just allowed someone to set your $loggedin, $admin, $user_name, $user_id ... variable in your code to any value they wanted. A person looking to save some typing by using extract is also likely to leave out escaping data being put into a query statement.
  21. Short answer - programming does not involve magic or the ability to go back in time. You cannot use a variable until after it has been assigned a value. You are trying to paste together a html document using php include statements for the various sections. That method is inflexible and limited in what it can do. A solution would be to form your dynamic output in php variables, then at the end of your code, produce the actual html document and echo the various php variables at the appropriate place in the html document. The following is an example of a pagination script that shows this method - <?php $title = "Pagination w/css links"; // 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>"; // get and condition any search term $search = isset($_GET['search']) ? trim($_GET['search']) : ''; $where_clause = ''; if($search != ''){ // form a simple LIKE '%search term%' comparison $where_clause = sprintf("WHERE name LIKE '%s%%'",mysql_real_escape_string($search)); } // define the main and count queries $main_query = "SELECT * FROM collages $where_clause"; $count_query = "SELECT COUNT(*) FROM collages $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); $main_content = ''; if($num_rows == 0){ // query matched no rows $main_content .= "There are no matching records to display on this page."; } else { $main_content .= "Your query matched $total_rows record" .($total_rows > 1 ? 's' : '').". "; $main_content .= "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)){ $main_content .= $row['name'] . '<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 // <li><a href="#" class="prevnext disablelink">« previous</a></li> // <li><a href="#" class="prevnext">« previous</a></li> if($requested_page > 1){ // 'first' page link $_GET[$pagination_name] = 1; // set/replace the pagination GET parameter (all other GET parameters unchanged) $pagination_links .= "<li><a class='prevnext' href='?" . http_build_query($_GET, '', '&') . "'><<</a></li> "; // 'prev' page link $_GET[$pagination_name] = $requested_page - 1; // set/replace the pagination GET parameter (all other GET parameters unchanged) $pagination_links .= "<li><a class='prevnext' href='?" . http_build_query($_GET, '', '&') . "'><</a></li> "; } else { // text only place holders $pagination_links .= "<li><a href='#' class='prevnext disablelink'><<</a></li> "; $pagination_links .= "<li><a href='#' class='prevnext disablelink'><</a></li> "; } // 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){ //<li><a href="#" class="currentpage">1</a></li> $pagination_links .= "<li><a href='#' class='currentpage'>$x</a></li> "; } else { // output page link $_GET[$pagination_name] = $x; // set/replace the pagination GET parameter (all other GET parameters unchanged) $pagination_links .= "<li><a href='?" . http_build_query($_GET, '', '&') . "'>$x</a></li> "; } } } // 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 .= "<li><a class='prevnext' href='?" . http_build_query($_GET, '', '&') . "'>></a></li> "; // 'last' page link $_GET[$pagination_name] = $total_pages; // set/replace the pagination GET parameter (all other GET parameters unchanged) $pagination_links .= "<li><a class='prevnext' href='?" . http_build_query($_GET, '', '&') . "'>>></a></li>"; } else { // text only place holders $pagination_links .= "<li><a href='#' class='prevnext disablelink'>></a></li> "; $pagination_links .= "<li><a href='#' class='prevnext disablelink'>>></a></li>"; } } ?> <html> <head> <title><?php echo $title; ?></title> <style type="text/css"> .pagination{ padding: 2px; } .pagination ul{ margin: 0; padding: 0; text-align: left; /*Set to "right" to right align pagination */ font-size: 16px; } .pagination li{ list-style-type: none; display: inline; padding-bottom: 1px; } .pagination a, .pagination a:visited{ padding: 0 5px; border: 1px solid #9aafe5; text-decoration: none; color: #2e6ab1; } .pagination a:hover, .pagination a:active{ border: 1px solid #2b66a5; color: #000; background-color: #FFFF80; } .pagination a.currentpage{ background-color: #2e6ab1; color: #FFF !important; border-color: #2b66a5; font-weight: bold; cursor: default; } .pagination a.disablelink, .pagination a.disablelink:hover{ background-color: white; cursor: default; color: #929292; border-color: #929292; font-weight: normal !important; } .pagination a.prevnext{ font-weight: bold; } </style> <body> <div><?php echo $search_form; ?></div> <div class="pagination"> <ul> <?php echo $pagination_links; // echo the links wherever you want in the content on your page ?> </ul> </div> <div><?php echo $main_content; ?></div> </body> </html>
  22. You should also change your database columns to DECIMAL so that the values will be stored as an exact value, rather than being converted to floating point.
  23. You need to have php's error_reporting set to E_ALL and display_errors set to ON in your master php.ini on your development system so that php will help you by reporting and displaying all the errors it detects. Your database column names are not exactly Owner and Name, so $phonecompany2->Owner and $phonecompany2->Name would be producing undefined property errors to alert you to the mismatch between your actual column names and the names you are using in your code.
  24. And after you correct how your editor is saving the files, remove the ob_start and ob_end_clean statements from your code. They don't have anything to do with fixing this problem. Also, go into your php.ini on your development system and turn off the output_buffering setting so that your development system matches your live site and you won't waste more time developing php code that won't work when you put it onto your live site.
  25. $stats holds an instance of the result object that the $db->execute() method creates internally (i.e. $result = new some_result_class();) and returns (i.e return $result;). Methods are like functions, they (optionally) accept input parameters (the query statement in this case), perform some processing (execute the query and hold the result resource from that query internally), and (optionally) returns a result (a custom result object in this case.) The result object (in $stats) has properties (values) and methods that you can access/call. $stats->EOF (End Of File) is a property that is set to TRUE when the ->MoveNext() property method has moved past the last row in the result set from the query. $stats->fields is a property that is an array with at least two indexes/keys - stsKey and stsValue. The properties $stats->fields['stsKey'] and $stats->fields['stsValue'] are set to each successive key and value that the query returned. The $stats->MoveNext() method fetches the next key/value pair from the result set that the query returned and sets the $stats->fields['stsKey'] and $stats->fields['stsValue'] properties with those values.
×
×
  • 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.