Read key in array – PHP

My array is:

[SCHOOL] => Array
  (
    [0] => Array(
      [SCHCODE] => 0001[QTY1] => 1
    )

    [17] => Array(
      [SCHCODE] => 0002[QTY1] => 10
    )

  )

The second array with key=17 is created automatically (it does not matter much) and the key gets a random value like 17 from a counter.
How can I read the previous key which in our case is 0 and increase it each time by one. So instead of 17 to write 1

PHP 8 Uncaught TypeError: mysqli_num_rows(): Argument #1 ($result) must be of type mysqli_result [duplicate]

After I moved my website from windows server and ubuntu and from php 7.3 to php 8 I get countless annoying fatal errors

I need to fix this VERY quickly

All of this isn’t helping:

PHP message: PHP Fatal error: Uncaught TypeError: mysqli_fetch_assoc(): Argument #1 ($result) must be of type mysqli_result, bool given

How to deal with mysqli problems? mysqli_fetch_array(): Argument #1 must be of type mysqli_result

this is the code:

    $queryReceiver = 
    mysqli_query($con, "SELECT userid,nickname,token FROM members JOIN android_notif ON members.userid = android_notif.last_online_id WHERE members.userid IN ($final) AND android_notif.blocked_userids NOT LIKE '%,$userid,%'");

        if(mysqli_num_rows($queryReceiver) > 0){

I get:

PHP message: PHP Fatal error:  Uncaught TypeError: mysqli_num_rows(): Argument #1 ($result) must be of type mysqli_result, bool given in /var/www/vhosts/yolol.de/httpdocs/do_post_comment.php:352nStack trace:n#0 /var/www/vhosts/yolol.de/httpdocs/do_post_comment.php

How to fix this afap without changing db or whatever?? Please help

How to create signature for twitter api

I’m trying to create a signature for the twitch api, but I don’t know what’s wrong

$this->timestamp = time();
$this->nonce = mt_rand();

    $base = 'POST' . "&" . rawurlencode('https://api.twitter.com/1.1/statuses/update.json') . "&" . rawurlencode('include_entities=true&')
        . rawurlencode("oauth_consumer_key=" . rawurlencode($this->consumer_key)
            . "&oauth_nonce=" . rawurlencode($this->nonce)
            . "&oauth_signature_method=" . $this->oauth_signature_method
            . "&oauth_timestamp=" . $this->timestamp
            . "&oauth_token=" . $this->access_token
            . "&oauth_version=" . $this->oauth_version
            . "&status=Hello%20Ladies%20%2b%20Gentlemen%2c%20a%20signed%20OAuth%20request%21"
        );

    dump("base string");
    dump($base);

    $key = rawurlencode($this->consumer_secret) . '&' . rawurlencode($this->token_secret);
    $this->signature = base64_encode(hash_hmac('sha1', $base, $key, true));

mysql delete rows using NOT IN with multiple columns

I’ve been trying to delete rows in a table where NOT IN php array.

basically, the table contains table_1_id, table_2_id, is_active

So my query is :

$delete = "
    DELETE FROM pivot
    WHERE (table_1_id, table_2_id) 
    NOT IN (
        ".implode(',', array_unique($table1Ids)).", 
        ".implode(',', array_unique($table2Ids))."
    ) AND is_active = 1
";

However, this query deletes all the rows EITHER table_1_id‘s value not in $table1Ids or table_2_id‘s value not in $table12ds.

I expected it to delete rows, STRICTLY to compare both table_1_id and table_2_id at the same time, not EITHER.

Sorry for bad explanation, seems too hard to put into words.

Installing Magento2 by command lin on MacOS – Error with command bin/magento setup:install

So I am trying to install Magento 2 for the first time on my new MacBook I have everything setup except for installing with the setup command bin/magento setup:install

I created a database and a user with privileges to that database with the mysql command, but after I run:

--base-url='http://127.0.0.1/magento2' 
--db-host='localhost' 
--db-name='magento2' 
--db-user='nick' 
--db-password='root' 
--admin-firstname=admin 
--admin-lastname=admin 
[email protected] 
--admin-user=admin 
--admin-password=admin123 
--language=en_US 
--currency=USD 
--timezone=America/Chicago 
--use-rewrites=1

I get this error message:

SQLSTATE[HY000] [1045] Access denied for user ‘nick’@’localhost’ (using password: YES)

In InstallCommand.php line 274:

Parameter validation failed

Since I have never installed Magento 2 on my own I don’t know what to do.
Oh yeah and I am using MAMP as server with Apache port 80 and MySQL port 3306

Set span to Shopify liquid Variable

I am trying to set span class “price” to Liquid variable if the if statement is true.

<p class="old-price"><span class="price-sep"></span><span class="price"></span></p>

I have tried this method to see if this “price” class in the if statement overrides the “price” class above because it comes after the above code. I’m new to Liquid but I know in JavaScript there is a way you can set text to “variable”, what is the way with Liquid ?

{% if dynamic_products.compare_at_price_max > dynamic_products.price %}
                <p class="old-price"><span class="price-sep"></span><span class="price">Box 
Value:{{ dynamic_products.compare_at_price | money }}</span></p>

How to download a file directly instead of reading it from the html

i have this code:

        $garages = $this->formatGaragesData($garageEntities);
        // Returns an array with multiple arrays in it which are containing values like name etc

        $fileName = 'garage_export.csv';

        header('Content-Type: application/csv');
        header('Content-Disposition: attachment; filename="' . $fileName . '"');
        header("Content-Transfer-Encoding: UTF-8");

        foreach ($garages as $garage) {
            foreach ($garage as $value) {
                echo $value;
            }
        }

this downloads my garage_export.csv file but it does not place the values in the correct columns, so i thought is there a way to download garage_export.csv directly instead of reading it from the html because in garage_export.csv the data is placed in the correct columns.

Any help or advice is welcome 😀

How to show the data properly in the table

hi i have an php code which is read an json field value and displayed in the table format my code is working fine but the data is not arranged properly how to fix this one can anyone help me on this

 $post_id = get_the_ID();

$dataproducts = get_field( “data_product”, $post_id);
$data = json_decode($dataproducts);

$table = '
<table class="company-sub-table">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
    <th>Name</th>
    <th>Description</th>
    <th>Uses Data Product</th>
    <th>Customer Type</th>
</tr>
</thead>
<tbody>
';
foreach ($data as $dataproducts_var) {
  foreach ($dataproducts_var->name as $name_of_dp)
  {
 
  echo "<script>console.log('Console: " . $name_of_dp . "' );</script>";
    $name_dp = $name_of_dp;
  echo "<script>console.log('Console: " . $name_dp . "' );</script>";
    $table .= '
        <tr>
            <td>' . $name_dp . '</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    ';
}
    
    foreach ($dataproducts_var->description as $description)
    {
        $description_to_print = $description;
        $table .= '
            <tr>
                <td></td>
                <td>' . $description_to_print . '</td>
                <td></td>
                <td></td>
            </tr>
            ';
    }
    foreach ($dataproducts_var->uses_data_product as $uses_dp)
    {
        $uses_dp_to_display = $uses_dp;
        $table .= '
            <tr>
                <td></td>
                <td></td>
                <td>' . $uses_dp_to_display  . '</td>
                <td></td>
            </tr>
            ';
    }
    foreach ($dataproducts_var->customer_type as $c_type)
    {
        $c_type_to_display = $c_type;
        $table .= '
            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td>' . $c_type_to_display . '</td>
            </tr>
            ';
    }
}
$table .= '
    </tbody>
</table>
';
echo $table;

this is the table looks like

this is the json field value———- [{“name”:[“JDLink “],”description”:[“Solution that fits any make/model of equipment, including older John Deere and non-John Deere equipment. Places essential machine information such as location, machine hours, and alerts at the usersu2019 fingertips, leaving them in complete control to increase machine productivity.”],”uses_data_product”:[“GPS Data, Equipment/Maintanence Data”],”customer_type”:[“Vehicle Fleet Operators”]},{“name”:[“Granular Insights”],”description”:[“John Deere’s telematics system supports operational improvements by providing information such as field ops data like hours, acres and quantities of inputs applied, and crops harvested. Premium services are sold at 6$ per Acre. “],”uses_data_product”:[“Farm Yeild Data”],”customer_type”:[“Farmers”]}]

Email Sending Issue on nginx Server

I have shifted my website to a new Nginx server with PHP 7.4, Apache 2.4, and OpenSSL 1.1.1n. If I try to send an email from default PHP settings it sends the email successfully but it will go to spam/junk which is fine with me. We use ZohoMail and Office365 on different cpanel accounts.

$mail->Encoding = "base64";
$mail->SMTPAuth = true;
$mail->Host = "smtppro.zoho.com";
$mail->Port = 465;
$mail->Username = '[email protected]';
$mail->Password = 'yourpassword';
$mail->SMTPSecure = 'SSL';
$mail->isSMTP();
$mail->IsHTML(true);
$mail->CharSet = "UTF-8";
$mail->From = "[email protected]";
$mail->FromName = 'Company';
$mail->addAddress('[email protected]');
$mail->Body="Test email sent successfully.";
$mail->Subject="Test Email";
$mail->SMTPDebug = 1;
$mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str"; echo "<br>";};
if(!$mail->Send()) {
    echo "Mail sending failed";
} else {
    echo "Successfully sent";
}

The server is not accepting any SMTP settings but the default PHP email works. Please guide me to solve this issue as I’m new to nginx servers.

symfony asset-component in controller: file not found

I’m using Symfony 5.3.9 and try to load a file into a Service-controller.
I use the assets-component with emptyVersionStrategy.

my filesystem:

/assets/vorlagen/XXX.html

My Service-Controller-Code:

$package = new PathPackage('/assets/vorlagen', new EmptyVersionStrategy());
$template = $package->getUrl($anzeige->getTemplate()->getDatei());
$handle = file_get_contents($template);

The error-Message:
Warning: file_get_contents(/assets/vorlagen/XXX.html): failed to open stream: No such file or directory

When I simply return $anzeige->getTemplate()->getDatei() the name of the file is correct
and

Eclipse PHP to work with Javascript syntax

I am looking for a plugin of some sort that would help with the highlighting of JavaScript elements and syntax within Eclipse 2022-03 (4.23.0). Currently using the IDE for PHP development proposes and want to ensure that whatever plugins have already been installed dont mess up my current IDE settings/customizations.
I have looked for various plugins (Sonarlint being the highest rating, but wont install) but no luck so far.

Any help with this would be highly appreciated.
Cheers

Converting a Time from a database to BST with PHP

So I’ve trying all sorts of combinations to get a date from my database (using WordPress) to display in British Summer Time and I cannot get anything to work.

Is there any simple solution that can take the date string and make sure that in Summer Time in the UK it’s an hour on from UTC time?

$classJson = $class->info;
$classJsonAsArray = json_decode($classJson, TRUE);

$classStartDate = strtotime($class->periodStart);
$classStartTime = date('H:i',$classStartDate);

So currently $class->periodStart returns: 2022-04-06 08:30:00

The time of that event should be 9.30am

All I need it to do is display the correct time, as at the moment, on the front end it displays as 8.30am.