How to display the text with the value at the same time from my dropdownlist select option tag?

I am trying to display these centimeters in my dropdownlist along with the price which was put on my value

<label>Select Height</label>
                  
                  <select name="psheight" id="psheight" style="width:50%;" class="form-control form-control-sm rounded-0" onchange="changeddl(this)"  >
                  <?php
                    $conn = $pdo->open();

                    try{
                      $now = date('Y-m-d');
                      $stmt = $conn->prepare("SELECT * FROM customize_ps_height");
                      $stmt->execute();
                      foreach($stmt as $row){
                          
                      ?>
                      
                        <option value="<?php echo $row['price'];?> <?php echo $row['height'];?>"><?php echo $row['height']; ?></option>
                        
                      <?php
                        
                     
                      }
                    }
                    catch(PDOException $e){
                      echo $e->getMessage();
                    }

                    $pdo->close();
                  ?>
                </select>
                  <div class="divheight" class="height-style"></div>
                <div class="divprice" class="price-style"></div>
<script>
  function changeddl($this){
    
$($this).next('.divheight').text($this.value>0?("Height: " + $this.value + " ₱"):"");
   $($this).next('.divprice').text($this.value>0?("Price: " + $this.value + " ₱"):"");

   
};
</script>

heres my output but i wanted also to display the centimeter which is selected

PHP – How to display messages from an array (API) with a timeout between them but push new incoming messages at the end of the queue [duplicate]

Let’s say I have an API response as an array.

$data = [
  ['id' => 1, 'message' => 'Message 1', 'displayed' => false ],
  ['id' => 2, 'message' => 'Message 2', 'displayed' => false ],
]

I want to display the messages to the frontend with a sleep between them.

But this data is real-time data so that new messages can be inserted from external systems. I want those new messages to be inserted at the end of the queue (before undisplayed messages).

How can I create a function that displays the $currentMessage?

Issue when converting mysql_fetch array to $wpdb->get results within WP Shortcode

I am looking to deliver a dropdown within the page of a WordPress Theme connecting to the backend WP Database using $wpdb and ob_start to bring through option values.

In order to do this I have had to convert mysql_fetch array to $wpdb->get results and use a Shortcode generated from a PHP Snippet plugin.

Code –

add_shortcode( 'get-city', function () {
    ob_start(); ?>
   <?php
    global $wpdb;
    $results = $wpdb->query("SELECT countryid FROM {$wpdb->prefix}city");?>
    <select name="city"> 
    <option>Select City</option> 
    <?php while($row=$wpdb->get_results($results)) {
           echo "<option value>{$row->city}</option>";
    }
    echo "</select>";
    
    return ob_get_clean();
});

The shortcode shows no errors and is able to be activated.

The dropdown shows on the page but then no options are presented for a user to select. Nothing is being brought through from the db.

I would really appreciate it if someone could point out the error.

Thanks in advance.

Convert stdClass object into a PHP array

I get this JSON back

stdClass Object ( [status] => stdClass Object ( [timestamp] => 2022-11-17T10:41:36.783Z [error_code] => 0 [error_message] => [elapsed] => 1 [credit_count] => 1 [notice] => ) [data] => stdClass Object ( [1] => stdClass Object ( [symbol] => w80iz51y4ka [id] => 1 [name] => omu2f57cwof [amount] => 1 [last_updated] => 2022-11-17T10:41:36.783Z [quote] => stdClass Object ( [GBP] => stdClass Object ( [price] => 0.436996948831 [last_updated] => 2022-11-17T10:41:36.783Z ) [LTC] => stdClass Object ( [price] => 0.201879205801 [last_updated] => 2022-11-17T10:41:36.783Z ) [USD] => stdClass Object ( [price] => 8977 [last_updated] => 2022-11-17T10:41:36.783Z ) ) ) ) )

I dont know how to handle this “stdClass Object”. There are a lot in.

At postmen I get this result

{
    "status": {
        "timestamp": "2022-11-17T08:53:52.920Z",
        "error_code": 0,
        "error_message": null,
        "elapsed": 1,
        "credit_count": 1,
        "notice": null
    },
    "data": {
        "2": {
            "symbol": "ymtwz9qdk3",
            "id": 2,
            "name": "9t5ci78gq36",
            "amount": 1,
            "last_updated": "2022-11-17T08:53:52.920Z",
            "quote": {
                "GBP": {
                    "price": 0.9733139411311549,
                    "last_updated": "2022-11-17T08:53:52.920Z"
                },
                "LTC": {
                    "price": 0.564631913659549,
                    "last_updated": "2022-11-17T08:53:52.920Z"
                },
                "USD": {
                    "price": 8956,
                    "last_updated": "2022-11-17T08:53:52.920Z"
                }
            }
        }
    }
}

I How can I convert this to an array in PHP?
I test a lot also some solutions from other posts. But I am lost a bit.

Thanks and kind regards
Markus

list customers who bought a specific product with name, email and quantity in woocommerce

I am looking for a simple script, to be used by the administrator, that can displays how many of a specific product has been bought in woommerce:

  1. product: 43764
  2. John doe, [email protected], bouhgt this item: 4 times
  3. dave dimp, [email protected], bouhgt this item: 2 times
  4. jane chimp, [email protected], bouhgt this item: 6 times

I have tried a alot of scipts but mainly they seem to be based to be used for customer or a specific user_id.

PHPStan reports undefined variable in PHPStan, but it’s defined in included script

I have an application where I define some variables in a file (a.php), then include this from another file (b.php). PHPStan is complaining about undefined variables.

Simplified example:

a.php:

$config['foo'] = 'bar';

b.php:

<?php

require 'a.php';

//new SlimApp($config)->run();
echo $config;

PHPStan says:

------ ---------------------------------------- 
  Line   b.php                                   
 ------ ---------------------------------------- 
  :6     Variable $config might not be defined.  
 ------ ---------------------------------------- 

Also: I don’t know why but if I remove the <?php line at the beginning of b.php, the warning goes away.

How can I have PHPStan realize that $config is actually defined?

Btw I am aware of this question. It is not the same problem as I am explicitly including the file where the variable is defined.

PHP deleting file from another harddrive

I’m trying to delete a file which is on another hard drive (F:)

$filePath = $_POST['path']; //F:/documents/918/20221117.pdf
unlink($filePath);

It just throws

Warning: unlink() [function.unlink]: No error in C:wwwdeleteFile.php on line 351

PHP Version is 5.1 (yup…)

What is correct Laravel Horizon Environment Configuration To Send Bulk Email(60,000+)

What is the best Laravel Horizon Environment configuration to send bulk email(60,000+) on a 4GB RAM server , i tried the below but it keeps crashing my redis server when sending the emails.

'supervisor-email' => [
            'connection' => 'redis',
            'queue' => ['bulkEmail', 'fastCron'],
            'balance' => 'auto',
            'processes' => 500,
            'tries' => 3,
            'minProcesses' => 1,
            'maxProcesses' => 500,
            'balanceMaxShift' => 1,
            'balanceCooldown' => 3,

with the above, 60,000+ email was queued to finish sending within 3-4hrs but My redis server keep crashing, What is the best configuration to use to avoid crashing and also make the queued job execute on time.
Thanks

How insert multiple file in database in same row

if(isset($_POST['submit'])){ 
    // File upload configuration 
    mkdir("public/$order_id", 0770, true);
    $targetDir = "public/$order_id/"; 
    $allowTypes = array('jpg','png','jpeg','gif'); 
     
    $statusMsg = $errorMsg = $insertValuesSQL = $errorUpload = $errorUploadType = ''; 
    $fileNames = array_filter($_FILES['files']['name']); 
    if(!empty($fileNames)){ 
        foreach($_FILES['files']['name'] as $key=>$val){ 
            // File upload path 
            $fileName = basename($_FILES['files']['name'][$key]); 
            $targetFilePath = $targetDir . $fileName; 
             
            // Check whether file type is valid 
            $fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION); 
            if(in_array($fileType, $allowTypes)){ 
                // Upload file to server 
                if(move_uploaded_file($_FILES["files"]["tmp_name"][$key], $targetFilePath)){ 
                    // Image db insert sql 
                    $insertValuesSQL .= "('".$order_id."','".$fileName."', NOW()),"; 
                }else{ 
                    $errorUpload .= $_FILES['files']['name'][$key].' | '; 
                } 
            }else{ 
                $errorUploadType .= $_FILES['files']['name'][$key].' | '; 
            } 
        } 
         
        // Error message 
        $errorUpload = !empty($errorUpload)?'Upload Error: '.trim($errorUpload, ' | '):''; 
        $errorUploadType = !empty($errorUploadType)?'File Type Error: '.trim($errorUploadType, ' | '):''; 
        $errorMsg = !empty($errorUpload)?'<br/>'.$errorUpload.'<br/>'.$errorUploadType:'<br/>'.$errorUploadType; 
         
        if(!empty($insertValuesSQL)){ 
            $insertValuesSQL = trim($insertValuesSQL, ','); 
            // Insert image file name into database 
            $insert = $db->query("INSERT INTO idcardprint (orderid,img1, date) VALUES $insertValuesSQL"); 
            if($insert){ 
                $statusMsg = "Files are uploaded successfully.".$errorMsg; 
            }else{ 
                $statusMsg = "Sorry, there was an error uploading your file."; 
            } 
        }else{ 
            $statusMsg = "Upload failed! ".$errorMsg; 
        } 
    }else{ 
        $statusMsg = 'Please select a file to upload.'; 
    } 
} 
?>

I Have try and get like this

img A img B
img 1
img 2

I want to get below table

img A img B
img 1 img 2

Why doctrine update entities when no setter has been called and change has been made?

PHP 8.1
Symfony 5.4
Doctrine 2.10

I’m profiling a PHP command (with blackfire) with dummy code for testing :

class MyCommand extends Command
{
    ...

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $query = $this->entityManager->createQuery(
            "SELECT t from AppEntityMyEntity t"
        );

        $query->setMaxResults(20);
        $i = 0;

        foreach ($query->getResult() as $transaction) {
            $i++;
        }
        
        $output->writeln($i);

        $this->entityManager->flush();

        return self::SUCCESS;
  }
  ...
}

So as you can see, no change made, no setter called.

But when I profile my command, I can see that doctrine made as many updates as there are entities :
Blackfire profiling output

It seems really unecessary, do you know what configuration could be causing this ?

Insert stament do not insert values in mysql table using pdo

I am new to pdo, and i wat to create a registration form all the code works including select qury but when i try to insert values to mysql I donot get any error but pdo insert do not insert any values in myaql table and always returns 0 rows insertd
`

<?php
function reg($err)
{
  global $pdo_conn;
  $fname = $err;
  $tab = 'user_details';
  $name = filter_var(strtoupper($_POST['name']), FILTER_SANITIZE_STRING);
  $cc_code = filter_var($_POST['cc_code'], FILTER_SANITIZE_NUMBER_INT);
  $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
  $key =  password_hash($_POST['key'], PASSWORD_DEFAULT);
  $lvl = 1;
  $date = date("Y-m-d");
  $reg_chk_stmt = 'SELECT * FROM '.$tab. ' WHERE email = :email';
  $reg_chk_qry = $pdo_conn->prepare($reg_chk_stmt);
  $reg_chk_qry->bindParam(':email', $email);
  $reg_chk_qry->execute();
  $reg_chk_rows = $reg_chk_qry->rowCount();
  if ($cc_code != $fname) {
    $err_1 = 'Your firm is not autorized';
  }else {
    //$err_1 = 'your firm is authorized';
    if ($reg_chk_rows != 0) {
      $err_1 = 'email is alredy registerd';
    }else{
      try{
        $reg_ins_stmt = "INSERT INTO " .$tab. " (name, email, pass, firm, lvl, created_on) VALUES (:name, :email, :pass, :firm, :lvl, :created_on)";
        $reg_ins_qry = $pdo_conn->prepare($reg_ins_stmt);
        $reg_ins_qry->bindValue(':name', $name, PDO::PARAM_STR);
        $reg_ins_qry->bindValue(':email', $email, PDO::PARAM_STR);
        $reg_ins_qry->bindValue(':pass', $key, PDO::PARAM_STR);
        $reg_ins_qry->bindValue(':firm', $cc_code, PDO::PARAM_INT);
        $reg_ins_qry->bindValue(':lvl', $lvl, PDO::PARAM_INT);
        $reg_ins_qry->bindValue(':created_on', $created_on, PDO::PARAM_STR);
        $reg_ins_echo = $reg_ins_qry;
        $reg_ins_qry->execute();
        }catch(PDOException $error){
          $err_1 = $error->getMessage();
        }
      $reg_ins_rows = $reg_ins_qry->rowCount();
      if ($reg_ins_rows != 0) {
        $err_1 = $reg_ins_rows;
      }else {
        $err_1 = $reg_ins_rows . $reg_ins_qry;
      }
    }
  }
  $reg_chk_qry = NULL;
  $reg_ins_qry = NULL;
  return $err_1;
}
define('db_host','localhost');
define('db_user','dbuser');
define('db_pass','dbpass');
define('db_name','dbname');
// Establish database connection.
  try
{
$pdo_conn = new PDO("mysql:host=".db_host.";dbname=".db_name,
db_user, db_pass,
array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
//echo "pdo connection works";
}
catch (PDOException $error)
{
exit("Error: could not connect to database");
}
$fname = 21828;
$error = reg($fname);
$header = 'Location: https://xyz.zy/index.php' . '?keyin_err=' . $error;
header($header);
 ?>

`

I tryed to run above code i donot get any error but my code donot insert any valuses to my mysql table

I need to choose between image and video from database with php (if – else) [closed]

I’m pulling pictures and videos from database. I want to create an if else with php and hide normal photo if there is video.

<?php
if (count($maschine->Bild)) {
  echo "<img src='<?php echo $lBild; ?>' class='latest-img' style='object-fit:scale-down; height: 100%' />";
} 
else
{
  echo "<video width='100%' controls autoplay muted loop src='<?php echo $lBild; ?>'></video>";            
}

?>

check if value exists in multidimensional array and find index

I have an multidimensional array like this:

$downloadArray = [
  "downloads1" => ["downloadnaam" => "fdgssgsfg"],
  "downloads2" => ["downloadnaam" => "eyetyy"],
];

I need to check if the value eyetyy exists in this array under the key downloadnaam
Then I need to find the index of this value and remove it from the array.

The expected result:

$downloadArray = [
  "downloads1" => ["downloadnaam" => "fdgssgsfg"]
];

I tried this:

$index = array_search($download->name, array_column($downloadArray, 'downloadnaam'));
if ($index !== null)
{
   unset($downloadArray[$index]);
   die("found index: " . $index);
}

$download->name contains 'eyetyy'
$downloadArray is my array
But it always dies and doesn’t show any index on screen.
Can anyone help me?

How to hide the div until the page load then show after the page completely loaded?

I want to hide the div till page load the i want show that div after the page is completely loaded, for that in my phtml file i tried this.

<div id='pilot' style="display : none">
    <div class="trustpilot-widget" data-locale="en-US" data-template-id="5406e6b0d049e042d5f" data-      businessunit-id="54c2a000ff00057c" data-style-height="28px" data-style-width="100%" data-theme="light">
<a href="https://www.trustpilot.com/review/www.mani.com" target="_blank" rel="noopener">Trustpilot</a>
    </div>
</div>
<script>
$(document).ready(function() {
    $("#pilot").show();
});
</script>

But its not working, any help can be appreciated.