mysql - PHP Session Array values -


i struggling script pull values out of session array , call information table in database.

i can values store in session no problem , looks when print it:

array ( [0] => 17 [1] => 18 [2] => 19 [3] => 20 [4] => 20 [5] => 19 [6] => 17 )

i have below php pull values out of array , pull records database appears breaking somewhere , unfortunately still quite noob @ php.

?php $action = isset($_get['action']) ? $_get['action'] : "";  if($action=='removed'){     echo "<div> removed cart.</div>"; }  if(isset($_session['cart'])){     $ids = "";     foreach($_session['cart'] $id){         $ids = $ids . $id . ",";     }      // remove last comma     $ids = rtrim($ids, ',');      $query = "select * events eventid in ({$ids})";     $stmt = $con->prepare( $query );     $stmt->execute();      $num = $stmt->rowcount();      if($num>0){         echo "<table border='0'>";//start table              // our table heading             echo "<tr>";                 echo "<th class='textalignleft'>product name</th>";                 echo "<th>price</th>";                 echo "<th>action</th>";             echo "</tr>";              //also compute total price             $totalprice = 0;              while ($row = $stmt->fetch(pdo::fetch_assoc)){                 extract($row);                  $totalprice += $eventcost;                  //creating new table row per record                 echo "<tr>";                     echo "<td>{$eventid}</td>";                     echo "<td class='textalignright'>{$eventcost}</td>";                     echo "<td class='textaligncenter'>";                         echo "<a href='removefromcart.php?id={$eventid} class='custombutton'>";                             echo "<img src='images/remove-from-cart.png' title='remove cart' />";                         echo "</a>";                     echo "</td>";                 echo "</tr>";             }              echo "<tr>";                 echo "<th class='textaligncenter'>total price</th>";                 echo "<th class='textalignright'>{$totalprice}</th>";                 echo "<th></th>";             echo "</tr>";          echo "</table>";         echo "<br /><div><a href='#' class='custombutton'>checkout</a></div>";     }else{         echo "<div>no products found in cart. :(</div>";     }  }else{     echo "<div>no products in cart yet.</div>"; } ?> 

i assuming breaking around query again i'm still quite noob @ this.

i trying pull out fields in table primary key trying link called 'eventid'. id's in array match records trying pull out.

i have copied code tutorial site why i'm struggling matching own.

thank in advance help.

it simple need use serialize save theme in database

http://www.php.net/manual/en/function.serialize.php

serialize make array text,you can save database when want use , call unserialize change array again

http://www.php.net/manual/en/function.unserialize.php


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -