Jump to content

David-London

New Members
  • Posts

    8
  • Joined

  • Last visited

David-London's Achievements

Member

Member (2/5)

0

Reputation

  1. I have upgraded to PHP8.o and have a plugin using the depreciated each() function. Would this be a correct refactor of this code? -- see the inline comments where I have made the changes // get the importable types $types = $this -> get_importable_post_types(); settype($types, 'array'); // I added this line if ( ! $types ) : _e('Sorry, there are no public post types that support post thumbnails.', 'plugin_default'); return; endif; _e('The default post type for new posts will be ', 'plugin_default'); if ( count($types) == 1 ): // only one so no need for selector // list($post_type, $post_type_name) = each($types); // I have taken this line out $post_type = key($types); // I added this line $post_type_name = current($types); // I added this line ?> Thanks for your help
  2. OK - thanks for reply. This is a plugin which I didn't write so I am just trying to update it. Just above the code this comment is written: // If there are sources, show a box of recently added Maybe I could replace that line of code with: Here is more of the code ... // If there are sources, show a box of recently added if ( count($this::$sources) > 0 ) : ?> <div id="tube-vc-recent-channels-module"> <h3> <?php _e( 'Recently added Channels &amp; Playlists', 'yt-revolution' ); ?> </h3> <ul style="list-style: none; padding-left:.25em;"> <?php $count = 0; foreach ( $this::$sources as $source ): $count++; if ( $count > 5 ): continue; endif;
  3. Hi all, I have recently upgraded to php 8.0 and some of the scripts in a wordpress plugin now don't work. One of them is because of count needing to be an array. Should I just change this code to this ? If not, what would be the correct sintax? Thanks
  4. Hi, I have this array: $cats = array( "A"=>'Business Expansion Specialist', "B"=>'Affiliate Page', "C"=>'Personal: Hobbies', "D"=>'Personal: Pets', "E"=>'Personal: Holidays', "F"=>'Personal: Sport', "G"=>'Personal: C.V.', "H"=>'Personal: Other', "I"=>'For Sale: Antiques', "Z"=>'Other' ); And then from a table I get the variable $cat_cd. $cat_cd contains 'F' so it refers to 'Personal: Sport' If I want to put that in $category, how would I write that? I thought it might be .... $category = $cats['$cat_cd']; I tried that and it didn't work . Thanks
  5. Thanks for he replies.I am converting from the old mysql_query to prepared statements with PDO so sorry for the basic questions !I usually try to research and find the answer and then post the problem.Sometimes that leads to a debate based around the (incorrectly) chosen method/function that I posted. Which I think happened here Maybe using a couple of simple examples will help me understand this. Examples:So. I have a table named cars.The column "plate" is the Primary Index.Other columns are not indexed See image attached.Environment:CENTOS 7.6 kvm [server] v80.0.15 Server Version: Apache/2.4.39Server version: 5.7.26 - MySQL Community Server (GPL)Server charset: UTF-8 Unicode (utf8)PHP version: 7.2.71) Assume there is a form which allows the userto enter a color name. So from that POST we geta variable $color.I want to ask the db if there is a row with color equal to $color in the table carsAnswer should be yes/no What should I use ?2) Secondly, a different script.I get the $color from the form and this time I want to ask ...~"how many rows have color equal to $color"I'd like the answer as 0 or 1 or 2 etc.Do I have to ask if there is a row first, (as in question 1) and then do a count on them if there is data or not ?What should be the code for this?3) Now I have another different form and it lets me enter the plate number (which is indexed)I get $plate variable.I just want to ask same as question (1) Is there a row with plate == $plate in table carsyes or no.I want to know if the code in (3) differs from (1) because of the index.Rather, than write the code I think it should be (like I did before), may I ask what you think it should beso that I can understand clearly? Hopefully I will "get" it.Many thanks
  6. Hi, I have two scripts using almost identical code. One of them works and finds the field (email) - the PRIMARY KEY (email) and the other doesn't (user_key) - not indexed Is this because PHP 7 needs to use only indexes in the WHERE part of SQL Query? Here are the two scripts - first one works $sql = 'SELECT access,fname FROM clients WHERE email=?'; $stmt = $connect->prepare($sql); $stmt->execute([$email]); $data_exists = ($stmt->fetchColumn() > 0) ? true : false; if ($data_exists) { // account found. $row = $stmt->fetch(); $access = $row['access']; $fname = $row['fname']; } else { $err_msg = 'Invalid Email Address and/or Password.'; $email = ''; $pass = ''; require_once ("login_fm.php"); exit; } [/PHP] This second one drops through to the ERROR page. $sql = 'SELECT email,fname,lname,confirm FROM clients WHERE user_key=?'; $stmt = $connect->prepare($sql); $stmt->execute([$the_key]); $data_exists = ($stmt->fetchColumn() > 0) ? true : false; if ($data_exists) { // Account found. $row = $stmt->fetch(); $email = $row['email']; $name = $row['fname'].' '.$row['lname']; $confirm = $row['confirm']; $_SESSION['auth'] = "yes"; $_SESSION['email'] = $email; $_SESSION['name'] = $name; $sql = 'UPDATE clients SET confirm = ?,log_count = log_count+1,last_date=? WHERE email=?'; $stmt= $connect->prepare($sql); $stmt->execute(['y',$today_time,$email]); require_once("index.php"); // SUCCESSFUL LOGIN: THIS LOADS THE START PAGE exit; } // end if else { $err_page_message = "ERROR - Account not found $the_key : $name"; require_once("err.php"); exit; } // end else May be it's a different reason - like I'm too tied ! On the second one. I could rewrite it to just try the update and fail-over to the ERROR page, But it would be nice to know why it isn't working. It's quite simple, I just want to check to see if a row exists with the condition given, that's all. I never had this problem the old mysql but the PDO seems a bit tricky or I'm just using the wrong code lol. Thanks
×
×
  • 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.