Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP - Select Array from List of Arrays in Foreach loop
    primarykey
    data
    text
    <p>I have an array of arrays. Each array contains a user's information (name, email, username, etc). When a user is logged in, the page needs to display the arrays in a table. (This is working fine)</p> <pre><code>&lt;table&gt; &lt;?php if(isset($_SESSION['logged_in_user'])) { echo '&lt;tr&gt;'; for ($i = 0; $i &lt; count($item_names); $i++) { if ($i == 8) continue; echo "&lt;th scope=\"col\"&gt;$item_names[$i]&lt;/th&gt;"; } echo '&lt;/tr&gt;'; $altrow = false; foreach ($contacts as $contact) { echo ($altrow) ? '&lt;tr class="alt"&gt;' : '&lt;tr&gt;'; $altrow = !$altrow; for ($i = 0; $i &lt; count($contact); $i++) { if ($i == 8) continue; echo "&lt;td&gt;$contact[$i]&lt;/td&gt;"; } echo '&lt;/tr&gt;'; } } ?&gt; &lt;/table&gt; </code></pre> <p>But I would also like the table to highlight the array(row) of the specific logged in user.</p> <p>I have tried (and failed):</p> <pre><code>&lt;table&gt; &lt;?php if(isset($_SESSION['logged_in_user'])) { echo '&lt;tr&gt;'; for ($i = 0; $i &lt; count($item_names); $i++) { if ($i == 8) continue; echo "&lt;th scope=\"col\"&gt;$item_names[$i]&lt;/th&gt;"; } echo '&lt;/tr&gt;' $altrow = false; foreach ($contacts as $contact) { if ($contact[1] == $_SESSION['logged_in_user']) { echo '&lt;tr class="highlight"&gt;' : '&lt;tr&gt;'; } else { echo ($altrow) ? '&lt;tr class="alt"&gt;' : '&lt;tr&gt;'; $altrow = !$altrow; for ($i = 0; $i &lt; count($contact); $i++) { if ($i == 8) continue; echo "&lt;td&gt;$contact[$i]&lt;/td&gt;"; } } echo '&lt;/tr&gt;'; } } ?&gt; &lt;/table&gt; </code></pre> <p>Am I not even close? Any help is appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload