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
I have a MySQL query that does a selection. I then have a $numrows variable which I have set to $numrows = mysql_num_rows($query);. If the value of $numrows == 0, I want the array variable I have to be set to empty. I tried setting the array variable to null and ""; but those don't work. Any suggestions? Thanks.
Empty an array
$array= array();
Delete it altogether
unset($array);
Related
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;
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 5 years ago.
Improve this question
I had this code
$loop ="5";
$value = "1";
how to insert value to db like this 1:1:1:1:1 (where loop have 5)
thanks
string $val_for_Db = "";
for ($i=0;$i<$loop;$i++) {
$val_for_Db = $val_for_Db."".$value.":";
}
$val_for_Db = substr($val_for_Db ,-1);
Now insert $val_for_Db to database.
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']).')';
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
I need to convert an array into associative array as first element should act as a key and second element should act as its value ?please tell me how i can do that
If you have only two elements (first and second as you mentioned), then you can do simply like this
$assoc = array($simple[0] => $simple[1]);
If you wanted to convert pairs of values like [1,2,3,4] to [1=>2,3=>4], then use this code snippet
$assoc = array();
for ($i = 0; $i < count($simple); $i=$i+2) {
$assoc[$simple[$i]] = $simple[$i+1];
}
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
I'm trying to obtain a column name EmailId from the table named Users. But it returns only the first string and nothing else?
PHP:
$sql="SELECT EmailId FROM Users;";
$result =mysqli_query($conn,$sql);
$col=mysqli_fetch_array($result);
The database has 3 email-ids but count($col) returns only 1. Why so?
Thanks in advance.
The database has 3 email-ids but count($col) returns only 1. Why so?
Because
$col=mysqli_fetch_array($result);
only fetch the first row according to the internal pointer of the dataset, and therefore
count($col)
returns 1 because $col is an array having 1 item.