Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP putting foreach() inside a table
    primarykey
    data
    text
    <p>First off, I'm really glad I stumbled on this website, your questions and answers helped me with my early assignments :) Now I need help :( What I was trying to do with my code was to create a table where it would have 3 columns "<strong>Product</strong>" "<strong>Description</strong>" "<strong>Price</strong>". Under each of the following headers, I would have my arrays "<code>$productImage</code>" be under the "<strong>Product</strong>" column and so forth. My problem is that I just can't seem to figure out how to make a table while using the <code>foreach()</code> function.</p> <p>Any help will be greatly appreciated!</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;?php $productImage = array('http://www.rudebaguette.com/assets/PlayStation4 FeaturedImage.jpg', 'http://cdn0.mos.techradar.futurecdn.net//art/games_consoles/Xbox%20One/Press%20shots/Xbox%20One%20family-580-90.jpg', 'http://www.blogcdn.com/de.engadget.com/media/2009/08/razer-naga-mmo-mouse-all-set-to-create-a-new-world-record11.jpg', 'http://cdn1.mos.techradar.futurecdn.net//art/gadgets/Google%20Glass/google_glass_grey-580-90.jpg', 'http://img1.targetimg1.com/wcsstore/TargetSAS//img/p/10/02/10029875.jpg'); $description = array('PS4 ', 'Xbox One', 'Razer Naga', 'Google Glass', 'Magic Bullet'); $price = array('400', '350', '70', '300', '50'); echo '&lt;table&gt;'; foreach ($productImage as $pic) { echo '&lt;tr&gt;'; echo '&lt;td&gt;'; echo "&lt;img src='".$pic."' width='200' height='180'&gt;"; echo '&lt;/td&gt;'; echo '&lt;/tr&gt;'; } foreach ($description as $des) { echo '&lt;tr&gt;'; echo '&lt;td&gt;'; echo $des; echo '&lt;/td&gt;'; echo '&lt;/tr&gt;'; } foreach ($price as $m) { echo '&lt;tr&gt;'; echo '&lt;td&gt;'; echo $m; echo '&lt;/td&gt;'; echo '&lt;/tr&gt;'; } ?&gt; </code></pre> <p> </p>
    singulars
    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.
    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