Reputation: 194
So I successfully connect to the database, get the results, but I want to use fields: name & Lastname in one option in Listbox.
I tried using + and & in between, but I only get the first field in the Listbox
<select>
<?php foreach($users as $user): ?>
<option value="<?= $user['name' ]; ?>"><?= $user['name']; ?></option>
<?php endforeach; ?>
</select>
My MYSQL fields are name & Lastname and I should get all of the options like so: (name Lastname)
Upvotes: 0
Views: 44
Reputation: 956
<select>
<?php foreach($users as $user): ?>
<option value="<?= $user['name' ] . ' ' . $user['Lastname']; ?>"><?= $user['name'] . ' ' . $user['Lastname']; ?></option>
<?php endforeach; ?>
</select>
The concatenation character in PHP is a single .
Upvotes: 1