I am making a dashboard using php and displaying it on webpage using html. For this I am taking some count values. Is !$value[" variable"] valid in php? How do i get the not of (!=) value? There is no other way to get the data. I am getting the values from a database.
print "<td><a href=\"$strBase and status!='Closed'\" target=\"_blank\">".$value[" ? "]."</td>";
I need to print !closed. Somehow I do not know how to pass that inside $value[].
If you want to use a variable as a key in order to retrieve a value from an array you can do as follows (I use a snippet of your code):
.$value[$myVar].
Where $myVar should be a string with the name of the key you want to retreive from $value
But anyhow, your question is pretty unclear so I'm not sure if this is what you are looking for.
You can check if the variable is empty(), i.e.:
if(empty($value["variable"])){
echo "variable is empty";
}
Related
While retrieving values from array without index in PHP I am getting nothing.
From my database value is stored like ["SCHOOL"] and I want to get just SCHOOL from this.
It's not treated as array instead it's treated as a string.
What will be the solution if want to treat this as array and get value of that array.
My Code is as follows :
$stream_arr = $res_tbl['streams'];
which gives result as ["SCHOOL"]
and I want just SCHOOL from this.
I am using code as $stream = $stream_arr[0];
and I get '[' this as result.
If I assign manual value to $stream_arr = ["SCHOOL"],
above code works and returns SCHOOL as expected.
But for results from my database is not working where result is same as the one I manually assigned.
To eliminate braces from the string you can use below code.
$stream_arr = '["SCHOOL"]';
$temp=explode('"',$stream_arr);
$val=$temp[1];
echo $val; //it will dispaly 'SCHOOL'.
But check the insert query(from the place you store data into db) that why it is storing with braces? if it is done by you as required then proceed else first fix that issue instead of eliminating braces in php code.
How to use a varible to store the value of the for loop?
for($i=1;$i<=$var;$i++)
How to get $i's value and store into another value and show its result?
I am a beginner of PHP and I want to improve my concept, I am very grateful if anyone can helps, Cheers!
Are you want dynamic variable or just a normal variable which will give you the out put like 12345678910
<?php
$var=10;
$a='';
for($i=1;$i<=$var;$i++){
$a.=$i;
}
echo $a;
?>
output: http://3v4l.org/2p8L6
or if you want dynamic variable then use following code to make a variable dynamic
${"num_" . $i} = $i;
output will be
$num_1=1;
$num_2=2;
$num_3=3;
etc
In plain English; PHP is updating the value stored in lopping variable automatically, and this is the whole idea behind using for loops, not only in PHP, but also in other programming languages.
Usually, you would want to use it (the variable $i) as a kind of a counter, and run code in the loop based on the iteration count.
Here's the link i want to decode:
https://api.instagram.com/v1/users/28855276/media/recent/?client_id=775829274b6f48c1ac2bf218dda60e16
Actually i've tried many methods to get the result i want but i failed to do so with PHP.
i need to extract a value from this json which should equal a certain variable
Example:
$variable = json_value
The Hard thing here that i want a duplicated value.
the value i need is:
profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_28855276_75sq_1348344197.jpg"
Do not know how to reach this value.
Here's it's place in the json file
{"username":"zedd","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_28855276_75sq_1348344197.jpg","id":"28855276","full_name":"Zedd"}
Please note that i've the username and id values already known.
Need to extract the profile_picture link to a PHP variable.
Please note: profile_picture is duplicated.
There is no duplication by me.
<?php
$array = json_decode('{"username":"zedd","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_28855276_75sq_1348344197.jpg","id":"28855276","full_name":"Zedd"}',true);
echo $array['profile_picture'];
?>
I'm trying to use some simple AJAX and then passing my variable through a HTML string.
Struggling to get some PHP included to print the value into the string. Been trying like this and the variable prints blank even though there is a value assigned to $user_id.
xmlhttp.open("GET","update.php?user=<?php $user_id ?>&q="+str,true);
Any suggestions on how I could do this or better solutions.
Thanks
you forgot echo:
xmlhttp.open("GET","update.php?user=<?php echo $user_id; ?>&q="+str,true)
I'm getting a few rows from the DB with an ajax call in PHP and I save the result to an array with javascript.
Then I make some changes in the data and wish to update the DB.
So I use another ajax call for that but I can't manage to access the fields inside the rows correctly.
When I try this I get nothing:
echo $bArray[$i].branchId;
When I try this:
echo json_encode($bArray[$i].branchId);
I get ArraybranchId instead of the field value.
What's the correct way to access the field with php?
Try either for array:
$bArray[$i]['branchId']
or for object:
$bArray[$i]->branchId
depending which type $bArray[$i] is (array or object). You have not written in your question, so I showed both ways.
I take it branchId is the name of the field, and you want the value for that field?
If so, it's:
echo $bArray['branchId']; or
echo $bArray[$i]['branchId']
Edit: Also, you'll need to make sure you're using mysql_fetch_assoc not mysql_fetch_array!