I'm trying to understand two things:
- If the following is possible;
- What I am doing wrong with implementing it.
I have an array in PHP which is manually coded:
$q[1] = 'Monday';
$q[2] = 'Tuesaday';
$q[3] = 'Wednesday';
I have a seperate mysqli multi-query
that is bringing back another set of data. As I iterate though the multi query and echo results, I need to include information that is within the manually coded PHP array, as detailed above - my current code is as follows:
echo "<tr><td class='qnum'><span class='bold'>". $n .".</span></td>
<td width='450px' > ". $q[$n] ." (<span class='italics'>". $row[0] ."</span>)</td>
<td class='set2'>".$row[9]."%</td>";
I have a pointer $n
that increases as the mysqli query loops through the results and I'm using the $q[$n]
to try and pull in the relevant data from the PHP query but it doesn't work. However, what is odd is that is I change $q[1] = 'Monday';
to $q = 'Monday';
and then reference $q
in my echo statement about - it works!!!
I've also included the mysqli code for reference below:
if ($mysqli->multi_query($query)) {
$n = 0;
do {
if ($result = $mysqli->store_result()) {
$i = 1;
$p = 1;
while ($row = $result->fetch_row()) {
$n++;
echo "<tr><td class='qnum'><span class='bold'>". $n .".</span></td>
<td width='450px' > ". $q[$n] ." (<span class='italics'>". $row[0] ."</span>)</td>
<td class='set2'>".$row[9]."%</td>";
echo "</tr>";
$result->free();
}
} while ($mysqli->next_result());
}
$mysqli->close();
Any thoughts, ideas, suggestions on where I am going wrong?
I didn't ensure that the first PHP manual array was actually correct - rookie error!