Jump to content

benanamen

Members
  • Posts

    2,134
  • Joined

  • Last visited

  • Days Won

    42

benanamen last won the day on October 12 2022

benanamen had the most liked content!

4 Followers

Contact Methods

  • Website URL
    http://galaxyinternet.us/
  • Yahoo
    phpfreaks@galaxyinternet.us

Profile Information

  • Gender
    Not Telling
  • Interests
    Email me at phpfreaks@galaxyinternet.us

Recent Profile Visitors

16,991 profile views

benanamen's Achievements

Prolific Member

Prolific Member (5/5)

146

Reputation

47

Community Answers

  1. The ORDER BY is pointless. You are only specifying a single ID in the WHERE clause. Update the method to return false if the query fails or if there are no results. You want to fail fast with a "guard clause". In your Home method check for false and redirect to the install if the condition matches. public function all_setting() { $query = $this->db->query("SELECT * FROM tbl_settings WHERE id=1"); if ($query === false || $query->num_rows() === 0) { return false; } return $query->first_row('array'); } if ($data['setting'] === false) { redirect('../install/'); } // Other code...
  2. Yeah, that's not going to work. Records can still be deleted. PM me the site URL and I will show you how and why.
  3. Php 7 has reached end of life. Tell them to upgrade you to Php 8.
  4. It's just a signature Barand. We are just arguing at this point. Grab a pint and enjoy your day. See you on another thread. 🙂
  5. For starters, the OP basically lied. The OP has ABSOLUTELY NOTHING to do with "Ratings in database ala Amazon". The OP admits it later on.. "In reality, this is a quiz composed of 15 questions each of varying lengths." And no, I didn't know it was incorrect for what the op was really trying to do. Had it really been a rating system, the query does indeed work to show ratings. Nevertheless, I won't be using AI content in future posts.
  6. Sometimes yes, but in this case (and my other posts last night) no since it wasn't my response. Allow me to explain... I have been experimenting with the ChatGPT AI (Artificial Intelligence). "My" post was 100% generated by the ChatGPT AI based on the full text of the OP. Obviously AI still has a ways to go and can be absolutely wrong or even provide "dangerous" code solutions. Still, it is pretty cool what it can do at this stage. You can check it out here https://openai.com/blog/chatgpt/
  7. You can use a combination of the preg_grep() function and regular expressions to select the range of data that you want. The preg_grep() function returns all elements of an input array that match a certain regular expression pattern. Here's an example of how you can use it to select the range of data that you want: $start = preg_grep("/gpononu/", $array); $start_key = key($start); $end = preg_grep("/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/", $array); $end_key = key($end); $result = array_slice($array, $start_key, $end_key - $start_key + 1); print_r($result); This will give you an array containing the lines from the input array that match the pattern "gpononu" (line 9 and 13) until the first line that matches the pattern for IP addresses (line 11 and 15) You can use array_slice with 3rd parameter as $end_key - $start_key + 1 , this will give you desired result.
  8. The @ symbol in front of the variables in this code is called an error suppression operator. It is used to suppress error messages that would be generated when trying to access an undefined array key. However, this can make it difficult to identify and fix errors in your code. Instead of using the error suppression operator, you can check if the key exists in the array before trying to access it. You can use the isset() function to check if a variable is set, and the array_key_exists() function to check if a key exists in an array. Here is an example of how you can update the code to check for the existence of the key before accessing it: function CreateSignature() { $sig = ""; if (isset($_SERVER["HTTP_USER_AGENT"])) { $sig .= $_SERVER["HTTP_USER_AGENT"]; } if (isset($_SERVER["HTTP_ACCEPT"])) { $sig .= $_SERVER["HTTP_ACCEPT"]; } if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) { $sig .= $_SERVER["HTTP_ACCEPT_LANGUAGE"]; } if (isset($_SERVER["HTTP_ACCEPT_CHARSET"])) { $sig .= $_SERVER["HTTP_ACCEPT_CHARSET"]; } $this->Signature = md5(Communication::GetIP() . $sig); } You can also use the ternary operator to shorten the code function CreateSignature() { $sig = isset($_SERVER["HTTP_USER_AGENT"]) ? $_SERVER["HTTP_USER_AGENT"] : ""; $sig .= isset($_SERVER["HTTP_ACCEPT"]) ? $_SERVER["HTTP_ACCEPT"] : ""; $sig .= isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]) ? $_SERVER["HTTP_ACCEPT_LANGUAGE"] : ""; $sig .= isset($_SERVER["HTTP_ACCEPT_CHARSET"]) ? $_SERVER["HTTP_ACCEPT_CHARSET"] : ""; $this->Signature = md5(Communication::GetIP() . $sig); }
  9. You can use a subquery to get the list of all possible ratings and then left join it with your reviews table to get the count of each rating. Here's an example query that should work: SELECT ratings.rating, COALESCE(reviews.count, 0) as count FROM ( SELECT DISTINCT rating FROM reviews ) as ratings LEFT JOIN ( SELECT rating, COUNT(*) as count FROM reviews GROUP BY rating ) as reviews ON ratings.rating = reviews.rating This query first gets a list of all distinct ratings from the reviews table, and then left joins it with a subquery that gets the count of each rating from the reviews table. The COALESCE function is used to replace any NULL values in the count column with 0, in case a rating doesn't have any reviews.
  10. This might work for you. https://linfo.sourceforge.net/
  11. This is really no different than what a banking app would do. Instead of money you have tokens. You are going to want to learn about Mysql Transactions. https://www.mysqltutorial.org/mysql-transaction.aspx
  12. I am still not sure what you are doing with out more details, but I am sure that whatever you are attempting to do with the posted code is not the way to do it. This should be to focus of your post. More details or some third party example is in order at this point. This just sounds like basic database management.
  13. What is the problem you are trying to solve by doing this?
  14. Good description of the problem. Now show us your code.
  15. The whole thing should not even be in your code at all. Error reporting setting should be set in php.ini
×
×
  • 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.