Hey guys I need help on passing multiple values for my PHP
http://s596.beta.photobucket.com/user/kingbookal/media/Capture.png.html?sort=3&o=0
That's the code from the 1st page and for the next page it is
$year = $_GET['yearlevel'];
I tried to alert the value but its null.
Please guide me well..
https://www.dropbox.com/sh/fokl2hnrjtpsfbn/Rcm8EfApm1
This is the link for my scripts
Do you want to echo the value from a key inside an array? Then you do like this:
echo $rowProfName['professor_name'];
If it doesn't return anything, you could check if a key exists in the array by using the following code:
if(!isset($rowProfName['professor_name']))
{
echo "Array key 'professor_name' is not set.";
}
If you want to check what your array contains, simply run this code:
$yourArray=array("value1","value2");
print_r($yourArray);
//If you want clean output as HTML, use this:
echo "<pre>";
print_r($yourArray);
echo "</pre>";
I hope I understood your question.
Related
For some strange reason I can't change the following JSON to a PHP array:
{"sides0":{"name_nl":"Voorkant100","name":"Frontside100","template_overlay":""},"sides1":{"name_nl":"Achterkant100","name":"Backside100","template_overlay":"1"}}
I've validated the json and it's valid.
First I post $product['sides'] to my page, containing:
"{\"sides0\":{\"name_nl\":\"Voorkant100\",\"name\":\"Frontside100\",\"template_overlay\":\"\"},\"sides1\":{\"name_nl\":\"Achterkant100\",\"name\":\"Backside100\",\"template_overlay\":\"1\"}}"
Then I use json_decode on it like this:
$sidearr = json_decode($product['sides'], true);
If I then do:
echo '<pre>';
print_r($sidearr);
echo '</pre>';
It prints the first part of my question.
Now I want to loop over it, but even this test shows nothing:
foreach($sidearr as $side){
echo 'test';
}
I tried testing if it even is an array with:
echo is_array($sidearr) ? 'Array' : 'not an Array';
echo "\n";
And it shows me that it is not an array. Why is that? I always thought using json_decode on a json string and add true inside the function turns it into a PHP array.
It prints the first part of my question.
Because $sidearr is a string now, decode it again, you'll get an array.
$sidearr = json_decode($sidearr, true);
I'm having some problems getting the data through my PHP loop.
<?php
$url = 'https://www.fibalivestats.com/data/1653309/data.json';
$content = file_get_contents($url);
$json = json_decode($content, true);
?>
<?php
foreach($json['totallds']['sPoints'] as $item); {
echo $item;
}
?>
The error I'm getting is an array to string conversion error. What I'm trying to get is the data from the sPoints array that will give me a Top 5 points scorers for a basketball game.
I'll build a table for this in HTML later but for now, it's not displaying the data at all and I'm getting errors. I feel like I may have confused arrays and strings too. Any thoughts about what I'm doing wrong? JSON file can be found in the $url variable.
Also if it helps, here's the link to where I have gotten the data from and what context the Top 5 is from https://www.fibalivestats.com/u/NSS/1653309/lds.html
Thanks!
Your $item is an array, so you can't just echo it like that. You can, however, echo its columns, for example:
foreach($json['totallds']['sPoints'] as $item) {
echo $item['firstName'] . ' ' . $item['familyName'];
}
Notice the removed semicolon between the foreach () and {.
Well, array to string conversion error means you're trying to echo an array.
If you see the return of the url you are looking at, you can verify that the "sPoints" key returns an array with several objects.
Try to change echo to print_r or var_dump to view entire data or complete your business logic.
Try changing:
echo $item;
to:
var_dump($item);
I want to show only 1 data in array.
My code right now:
var_dump($ranked);
In others cases, I have used echo $ranked->tier but in array this won't work.
You can do it like this:
echo $ranked['tier'];
var_dump($ranked['tier']);
or:
echo $ranked['tier'];
Can someone tell me how I can loop through the below array?
http://pastebin.com/rhaF5Zdi
I've tried with out luck:
$_data = json_decode($_data);
foreach ( $_data as $tweet )
{
echo "{$tweet->text}\n";
}
thanks
ps: im follwoing this php script.
http://mikepultz.com/2013/06/mining-twitter-api-v1-1-streams-from-php-with-oauth/
hers another paste bin on the array. there seems to be multiple arrays happening
http://pastebin.com/dduzhpqY
It looks like you might be creating a PHP stnd object instead of an array
//this will create a php standard object
$objOfData=json_decode($json);
Instead Use the version below: (Notice the the 2nd parameter is TRUE)
$associativeArray=json_decode($json, TRUE);
This will turn the object into an associative array and you can access fields like so:
$id=$associativeArray['id'];
More info here: json_decode
The code in posted link is not JSON, but it is output of print_r() function. PHP has no invert function to print_r(), but on php.net in print_r() documentation's comments you can find some user-made functions which can read it.
For example this one:
http://www.php.net/manual/en/function.print-r.php#93529
I hope it will help. Good Luck :)
Ended up using:
if(array_key_exists('text', $_data)){
echo 'Tweet ID = '.$_data['id_str'];
echo 'Tweet Text = '.$_data['text'];
echo '<br /><br />';
}
cheers
I'm breaking my brain on a array from a query in MYSQL that i want to pass to a javascript array.
In the query i select the array with a GROUP CONCAT and the outcome looks like:
1358121600,1,1,0,0,0,0,0,0,1358380800,2,2,0,0,0,0,0,0,1358640000,1,1,0,0,0,0,0,0,1360454400,3,3,0,0,0,0,0,0,1360972800,1,1,0,0,0,0,0,0
But if i use JSON_Encode like this:
<?php echo 'var prijzen = new Array('.json_encode($array_prijzen).');'; ?>
I looks like the array is filled and i can also alert the array, but if i alert prijzen[0] it gives "undefined".
The following code should fix your problem:
<?php echo 'var prijzen = ['.$array_prijzen.'];'; ?>
Building on #datasages 's answer. If $array_prijzen is a genuine php array, then the following will work. I think datasages's answer is based on the fact that your variable named $array_prijzen is actually a string (which seems to be the case). But if it's an array, then do the following (i created a five element array as an example):
<?php $array_prijzen = array(1358121600,1,1,0,0); echo 'var prijzen = ['.implode(",",$array_prijzen).'];'; ?>