I’m running PHP 5.4.4 on my server, compiled with ./configure. I have PDO with the SQLite 3.7.7.1 driver. I’ve created the following tables.
CREATE TABLE IF NOT EXISTS
login (
id PRIMARY KEY ON CONFLICT REPLACE,
given_name,
family_name,
gender
);
CREATE TABLE IF NOT EXISTS
address (
id,
street,
city,
state,
zip,
FOREIGN KEY(id) REFERENCES login(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS
certification (
id,
certification,
certification_expiration,
FOREIGN KEY(id) REFERENCES login(id) ON DELETE CASCADE
);
And this view.
CREATE VIEW "members" AS SELECT
login.id, login.given_name, login.family_name, login.gender,
address.street, address.city, address.state, address.zip,
certification.certification, certification.certification_expiration
FROM
login, address, certification
WHERE
login.id = certification.id
AND
login.id = address.id
I am querying the view like this:
<?php foreach ($sql->query('SELECT * FROM members;') as $row): ?>
<tr>
<?php foreach ($row as $index => $col): ?>
<td><?=$index;?>.<?=$col;?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
And it’s producing an output like this.
<tr>
<td>id.123456789012345678901</td>
<td>0.123456789012345678901</td>
<td>given_name.Mark</td>
<td>1.Mark</td>
<td>family_name.Tomlin</td>
<td>2.Tomlin</td>
<td>gender.Male</td>
<td>3.Male</td>
<td>street.1 Some Lane</td>
<td>4.1 Some Lane</td>
<td>city.Anywhere</td>
<td>5.Anywhere</td>
<td>state.NY</td>
<td>6.NY</td>
<td>zip.12345</td>
<td>7.12345</td>
<td>certification.AEMT-P</td>
<td>8.AEMT-P</td>
<td>certification_expiration.2015-07-31</td>
<td>9.2015-07-31</td>
</tr>
I’d like to know, why it’s giving me id. and 0., and given_name. and 1., and is there anything I can do the filter this behavior out from the query? I’d like to get just id. or just 0. but not both types.
This fixed it
Hat tip, biziclop for the assist.