Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As I see, you don't need define class, you can do something that Gustav mentioned. (you must first <em>initiate an object</em> and then call the method)</p> <p>I think it is better that you use out of class <strong>function</strong>, or using <strong>static method</strong>, instead.</p> <p> <pre><code>session_start(); $sessionID = $_COOKIE['PHPSESSID']; class DB_Functions { private $db; //put your code here //constructor static function initDb() { require_once 'DB_Connect.php'; //connecting to database $this-&gt;db = new DB_Connect(); $this-&gt;db-&gt;connect(); } public static function getCart(){ $query ="SELECT * FROM carrito ORDER BY id_pelicula"; $result = mysql_query($query) or die(mysql_error()); $no_of_rows = mysql_num_rows($result); if($no_of_rows &gt; 0) { while ($row = mysql_fetch_assoc($result)) { $totalItems = $totalItems + 1; $movieTotalPrice = $movieTotalPrice + $row['precio_pelicula']; } echo ("Artículos: &lt;b id='cantArticles'&gt;"+$totalItems+"&lt;/b&gt;&lt;otal: $ &lt;b id='totalPriceArticles'&gt;"+$totalPrice+"&lt;/b&gt;&lt;/a&gt;"); } else { return false; } } </code></pre> <p>or using without declaring them in class <pre><code>session_start(); $sessionID = $_COOKIE['PHPSESSID']; //put your code here function initDb() { require_once 'DB_Connect.php'; //connecting to database $db = new DB_Connect(); $db-&gt;connect(); } function getCart(){ $query ="SELECT * FROM carrito ORDER BY id_pelicula"; $result = mysql_query($query) or die(mysql_error()); $no_of_rows = mysql_num_rows($result); if($no_of_rows &gt; 0) { while ($row = mysql_fetch_assoc($result)) { $totalItems = $totalItems + 1; $movieTotalPrice = $movieTotalPrice + $row['precio_pelicula']; } echo ("Artículos: &lt;b id='cantArticles'&gt;"+$totalItems+"&lt;/b&gt;&lt;otal: $ &lt;b id='totalPriceArticles'&gt;"+$totalPrice+"&lt;/b&gt;&lt;/a&gt;"); } else { return false; } } </code></pre>
    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.
    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