Note that there are some explanatory texts on larger screens.

plurals
  1. POKohana set sessions and database
    primarykey
    data
    text
    <p>i'm creating a small shopping cart and i'm saving my products in a session (no database). My session sets the product id. But how can get the correct product from my database that matches the product id in my stored session?</p> <p>Code:</p> <pre><code>foreach ( (isset($shopcart) &amp;&amp; is_array($shopcart) &amp;&amp; count($shopcart) &gt; 0) ? $shopcart : array() as $item ) { $this-&gt;template-&gt;shopcart = $shopcart; } </code></pre> <p>.</p> <pre><code>&lt;?php if( isset( $shopcart ) ): ?&gt; &lt;?php foreach ($shopcart as $item): ?&gt; &lt;?php echo $item['id'] ?&gt; &lt;?php endforeach ?&gt; &lt;?php endif; ?&gt; </code></pre> <p>EDIT:</p> <pre><code> foreach ( (isset($shopcart) &amp;&amp; is_array($shopcart) &amp;&amp; count($shopcart) &gt; 0) ? $shopcart : array() as $item ) { $this-&gt;template-&gt;shopcart = DB::select()-&gt;where('id', 'IN', $item['id']) -&gt;from('products')-&gt;execute(); //$this-&gt;template-&gt;shopcart = $shopcart; } </code></pre> <p>Database_Exception [ 1064 ]: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''5'' at line 1 [ SELECT * FROM <code>products</code> WHERE <code>id</code> IN '5' ]</p> <p>EDIT 2:</p> <pre><code>$this-&gt;template-&gt;shopcart = array(); if (count($shopcart)) { $this-&gt;template-&gt;shopcart = DB::select() -&gt;where('id', 'IN', $item) -&gt;from('products') -&gt;execute(); } </code></pre> <p>Template:</p> <pre><code>&lt;?php if( isset( $shopcart ) ): ?&gt; &lt;?php foreach ($shopcart as $item): ?&gt; &lt;?php echo $item['id'] ?&gt; //This is the product id in my saved session but i need to get the name from the database &lt;?php endforeach ?&gt; &lt;?php endif; ?&gt; </code></pre>
    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.
 

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