Guest User

Untitled

a guest
Apr 18th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.44 KB | None | 0 0
  1. <?php
  2.         if(!isset($_SESSION["productSelected"]))
  3.         {
  4. ?>
  5.         <b>No item(s) in basket!</b>
  6. <?php
  7.         }
  8.         else{
  9.         $conn = pg_connect("host=db.dcs.aber.ac.uk port=5432 dbname=teaching user=csguest password=rohishe");
  10. ?>
  11. <table border='1'> <tr><th>ID#</th><th>Title</th><th>Platform</th><th>Description</th><th>Price (&pound;)</th><th>User</th></tr>
  12. <?php
  13. // begin debugging products //
  14. echo '<pre>' . print_r($_SESSION['productSelected']) . '</pre>';
  15. //end debugging products //
  16.  
  17.         foreach($_SESSION["productSelected"] as $id){
  18.         $res = pg_query ($conn, "select * from CSGames WHERE refnumber='$id' order by refnumber");
  19.         while ($row = pg_fetch_row($res))
  20.         {
  21. //debug each row returned //
  22. echo '<pre>' . print_r($row) . '</pre>';
  23. //end debugging each row returned //
  24.  
  25.             echo "<tr>";
  26.            
  27.             for ($j = 0; $j < pg_num_fields($res); $j++)
  28.             {
  29.                
  30.                 echo "<td>" . $row[$j]  . "</td>";
  31.             }
  32.             echo "</tr>";
  33.            
  34.         }
  35.  
  36. //are you 100% sure this is correct?
  37. //I'm pretty sure that pg_fetch_row returns a standard array (indexed with numbers)
  38. //rather than with names
  39. //Don't you have to use pg_fetch_assoc to retrieve items as an associative array?
  40. //also, you've used numbers up there ^^ in the forloop, which makes me think this is the issue
  41.         $total += $row['price'];
  42.  
  43.         }
  44. ?>
  45. </table>
  46. <!--</form>-->
  47. <form action='clearBasket.php' method='post'>
  48. <p><input type='submit' value='Clear Basket' /></p>
  49.         </form>
  50. <?php
  51.         }      
  52. ?>
Add Comment
Please, Sign In to add comment