Unable to populate select list with correct values from array.

HI,
I am obviously very challenged with objects/arrays and am having another issue that I've tried about a thousand combinations to make work but still not working.

My goal is to populate a select list from a table column. I get very close but just can't get the syntax right no matter what I try.

Doing a var_dump of the data I'm trying to extract the values from I get this (which is expected):
array(11) { [0]=> object(stdClass)#625 (2) { ["group"]=> string(13) "payment_types" ["values"]=> string(32) "["Monthly","Bi-weekly","Weekly"]" } [1]=> object(stdClass)#626 (2) { ["group"]=> string(11) "drive_types" ["values"]=> string(77) "["Front Wheel Drive","Rear Wheel Drive","All Wheel Drive","Four Wheel Drive"]" } [2]=> object(stdClass)#627 (2) { ["group"]=> string(10) "warranties" ["values"]=> string(95) "["Remainder of Factory Warranty","Has Extended Warranty","Warranty is Available","No Warranty"]" } [3]=> object(stdClass)#628 (2) { ["group"]=> string(5) "gears" ["values"]=> string(82) "["3 Speed","4 Speed","5 Speed","6 Speed","7 Speed","8 Speed","9 Speed","10 Speed"]" } [4]=> object(stdClass)#629 (2) { ["group"]=> string(10) "fuel_types" ["values"]=> string(168) "{"Gasoline Fuel":"Gas","Diesel Fuel":"Diesel","Hybrid Fuel":"Hybrid","Flex Fuel Capability":"Flex Fuel Capable","Electric Fuel":"Electric","Propane Fuel":"Natural Gas"}" } [5]=> object(stdClass)#630 (2) { ["group"]=> string(18) "transmission_types" ["values"]=> string(40) "["Automatic","Manual","TipTronic","CVT"]" } [6]=> object(stdClass)#631 (2) { ["group"]=> string(6) "extras" ["values"]=> string(78) "["4x4","AWD","Turbo","Convertible","Cabriolet","Quattro","TDI","Supercharged"]" } [7]=> object(stdClass)#632 (2) { ["group"]=> string(9) "condition" ["values"]=> string(35) "["Excellent","Good","Fair","As Is"]" } [8]=> object(stdClass)#633 (2) { ["group"]=> string(10) "truck_cabs" ["values"]=> string(271) "["Regular Cab","Extended Cab","Crew Cab","--- Ford Specific ---","Super Cab","SuperCrew","--- Dodge Specific ---","Quad Cab","Mega Cab","--- Mazda Specific ---","Cab Plus","--- Nissan Specific ---","King Cab","--- Toyota Specific ---","Access Cab","Double Cab","CrewMax"]" } [9]=> object(stdClass)#634 (2) { ["group"]=> string(21) "vehicle_option_groups" ["values"]=> string(81) "["Comfort","Convenience","Entertainment","Safety","Exterior","Truck, Van & Jeep"]" } [10]=> object(stdClass)#635 (2) { ["group"]=> string(10) "passengers" ["values"]=> string(52) "["1","2","3","4","5","6","7","8","9","10","11","12"]" } } 

Open in new window


The particular select list I'm trying to populate is for 'Passenger Capacity' which is the last in the dump.

When I do the following in an effort to populate my select list I get this as a result:

sample pic of select list
To get it to populate like the sample pic, the code I'm using is:
@foreach ($configuration as $passengers)
<option  value="{{ $passengers->values }}" > {{ $passengers->values }}</option>
@endforeach

Open in new window


Can you see what I should be doing to drill down to the passanger capacity values and input them into the select?

Thanks as always. I very much appreciate the help.
LVL 1
tjyoungAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kim WalkerWeb Programmer/TechnicianCommented:
Doing a var_dump of the data I'm trying to extract the values from I get this...
Is the "data you're trying to extract" in the variable $configuration? In other words, is the var_dump you posted in your question the result of
var_dump($configuration);

Open in new window

If so, $configuration contains an array of objects, each object contains two key->value pairs (group and values) and each value is a string. I believe you've already received help in converting the values string into an array.

So the first step is to iterate through the $configuration array and look for the object which has a group value of passengers
foreach ($configuration as $group) {
	if ($group->group === "passengers") {
		// convert the values string into an array and
		// iterate through this array to echo an option for each value
	}
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tjyoungAuthor Commented:
Yes thats totally correct.
But after
if ($group->group === "passengers") {
I can't see how to get the second step? I see I'm checking if the group is "passengers'.
Now that it is, how do I refer to it?

Sorry being a newbie is painful :)
0
tjyoungAuthor Commented:
Hi, after much suffering I figured it out lol

I can output the correct variables using standard php conditional statements ie:

<select data-placeholder="Choose cab style..."  class="select" name="cab_style" id="cab_style" >
	@if(!isset($vehicle->cab_style))
		<option></option>
	@endif
	
	<?php 
		foreach ($configuration as $group) {
			if($group->group === "truck_cabs"){
				$cabs = json_decode(($group->values));
					for ($i = 0; $i < count($cabs); ++$i) {
						echo "<option  value='$cabs[$i]'> $cabs[$i]</option>";
					}
				}
			}
	?>
</select>

Open in new window


But doing the same thing the laravel blade way I get $cabs variable isn't defined. I have a few of these type of arrays so was hoping to keep to the blade method throughout.
Any idea what the difference may be? Also if you see a better 'condensed' version to get there, please let me know. Thanks very much!

<select data-placeholder="Choose cab style..."  class="select" name="cab_style" id="cab_style" >
	@if(!isset($vehicle->cab_style))
		<option></option>
	@endif

	@foreach ($configuration as $group)
		@unless($group->group === "truck_cabs")
			$cabs = json_decode(($group->values))
				@for ($i = 0; $i < count($cabs); ++$i)
				<option  value='{{ $cabs[$i] }}'> {{ $cabs[$i] }}</option>
				@endfor
		@endunless
	@endforeach
</select>

Open in new window

0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Kim WalkerWeb Programmer/TechnicianCommented:
This is extremely complex for a "newbie." And your data isn't really conducive for this type of manipulation. Or is your data a database query result? If so, there are better ways to navigate through them. Is $configuration the result of a database query? If so, we need to change gears here -- please post the line of code that begins with or contains "$configuration=".
0
tjyoungAuthor Commented:
the pointer got me going along the right direction and way of thinking. Many thanks
0
Kim WalkerWeb Programmer/TechnicianCommented:
Sorry, I am not familiar with Laravel Blade. I was not aware that they do not use PHP.
0
tjyoungAuthor Commented:
Hi, yes the configuration is the result of a database query.
Configuration is one of the objects I'm passing back from my laravel controller. It's saved in the database that way.

Here is a screen shot of that table:
the format/data is 'adopted' from an earlier version of the site. The table are general configuration settings for various fields
table
They are used to populate various select menus etc. for a used car inventory form
0
tjyoungAuthor Commented:
Being that these values seldom change, is there a better way I should store the values so I can step through them easier in the form layout? I also just noticed the gas values aren't saved exactly the same...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Laravel

From novice to tech pro — start learning today.