How to get rating value (WordPress) [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
$rating = $rowsRaing;
Array
(
[0] => stdClass Object
(
[ratting] => 2.5
)
)
I want rating value.
I want user average number of ratting help me
Thanks

Your query should be
$rowsRaing = $wpdb->get_results("select avg(ratting) as rating from tablename where id='".$_REQUEST['id']."'");
$rat=$rowsRaing;
$RatingVal = $rat[0]->rating;
By using this variable you get the avg number of ratting
"$RatingVal"

It's var of object inside array, so:
$yourRatingValue = $rat[0]->rating;

Related

firstOrNew where MONTH and YEAR laravel [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 months ago.
Improve this question
$matchThese = array('product_id' => 8789, 'MONTH(date_created)' => '04');
$result = ExpiryPrepayment::firstOrNew($matchThese);
$result->payment_status = 1;
$result->save();
***====>'MONTH(date_created)' => '04'***
Help me get condition only month or year in column date_created
Why are you sending an array at a firstornew? This is basically a string that you are building an array with in the eloquent. Inserting an array will not work. Really the product_id should be a unique so you only need that value in your where.
So it would be something like this...
firstOrNew(['product_id' => $product_id]);
$product_id being the variable of the unique id.
Then if you have tons of products to add just loop over the array of product ids and it will either make a new row at your save or update the product when it finds it first.

How to convert array to different type [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
i have Array ( [0] => dev2 [1] => dev3 [2] => dev4 )
how to convert to ["dev2","dev3","dev4"]
$old_array = array( 'dev2', 'dev3', 'dev4');
$new_array = json_encode($old_array);
echo $new_array;
I hope this is what you want.

PHP Select MYSQL select id from Array [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Hello I have this array:
$_SESSION['id'] = array();
I would like to select all array ID'S and then select them from the database.
How to do it? I have no idea..
$sql='select name from table where id in ('.implode(",",$_SESSION['id']).')';

Echoing several variable in random order [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm making simple test script with PHP+mysql.
The script gives the question and SELECT with 4 options (answers).
1 of them is correct, 3 others are incorrect, retrieved from mysql table.
I have 4 variables and all works fine, but I need to retrieve these variables in random order.
$variable1='1';
$variable2='2';
$variable3='3';
$variable4='4';
Just need some direction what to learn, what method to use.
Many thanks in advance
SELECT data from MySQL
Store in an associative array
shuffle the array
http://codepad.org/6R9LsGIy
<?php
$arrAnswers = array("a", "b", "c", "d");
shuffle($arrAnswers);
print_r($arrAnswers);
/* Example Ouput:
Array
(
[0] => b
[1] => d
[2] => a
[3] => c
) */
As you've said you have these variables;
$variable1='1';
$variable2='2';
$variable3='3';
$variable4='4';
$arrAnswers = array($variable1,$variable2,$variable3,$variable4);
There are more elegant ways, but with the information given, this is the best I can do :)

How can I access the id value in this array? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
When I do a print_r I get this array:
Array (
[0] => Array (
[id] => 5280
)
)
How can I access the id value with PHP?
You can access it like this
$id_value = $your_array[0]['id'];
Try
$mapped = array_map("current",$array);
echo $mapped[0];
This is useful if you have multiple arrays on the root array
eg: Array(Array(),Array()..)

Categories