Note that there are some explanatory texts on larger screens.

plurals
  1. POStore variables within a class from a query
    text
    copied!<p>I have an images class in which I want to run a query once the class is initiated (on login), and then <code>store</code> the variables such as <code>profile_picture_thumb</code> .etc in the class, or atleast access them in other functions via <code>this</code>. The following is not working, and returns the <code>this</code> fields as blank.</p> <pre><code>class Images { var $main_prepend = 'm_'; var $thumb_prepend = 't_'; var $default_ext = 'jpg'; var $cropfactor; private $prepLocation = ''; private $profile_picture_thumb = ''; private $profile_picture_large = ''; private $facebook_id = ''; public function __construct() { $sql = Nemesis::select("profile_picture_thumb, profile_picture_large, facebook_id", "users", "id = '{$_SESSION[user_id]}'"); list($profile_picture_thumb, $profile_picture_large, $facebook_id) = $sql-&gt;fetch_row(); $this-&gt;profile_picture_thumb = $profile_picture_thumb; $this-&gt;profile_picture_large = $profile_picture_large; $this-&gt;facebook_id = $facebook_id; if (local()) { $prepLocation = XAMPP; } else { $prepLocation = ''; } } public function profilePic($show = true, $delete = false) { if ($show) { echo '&lt;script type="text/javascript"&gt;$(function() { $("#profile-picture").tipsy({fade: true}); });&lt;/script&gt;'; if (is_file(ROOT . $this-&gt;profile_picture_thumb)) { echo '&lt;img src="' . reduce_double_slashes('../' . $this-&gt;profile_picture_thumb) . '" id="profile-picture" class="profile-picture" title="Your Profile Picture"&gt;'; } elseif (!empty($this-&gt;facebook_id)) { // if there is no profile picture set, and user has listed fb profile picture, get profile picture $fb_p_thumb = "http://graph.facebook.com/{$facebook_id}/picture"; $fb_p_large = "http://graph.facebook.com/{$facebook_id}/picture?type=large"; echo '&lt;img src="' . $fb_p_thumb . '" id="profile-picture" class="profile-picture" title="Facebook Profile Picture"&gt;'; } else { echo '&lt;img src="images/50x50_placeholder.gif" id="profile-picture" class="profile-picture" title="Click to add profile picture"&gt;'; } } if ($delete) { if (is_file(ROOT . $this-&gt;profile_picture_thumb) || is_file(ROOT . $this-&gt;profile_picture_large)) { if (!unlink(ROOT . $this-&gt;profile_picture_thumb) &amp;&amp; !unlink(ROOT . $this-&gt;profile_picture_large)) { $msg-&gt;add('e', "Could not delete user profile picture!"); } } else { $msg-&gt;add('e', "Files not found in directory."); } } } </code></pre> <p>I have also tried:</p> <pre><code>public function __construct() { static $prepLocation = ''; static $profile_picture_thumb = ''; static $profile_picture_large = ''; static $facebook_id = ''; $sql = Nemesis::select("profile_picture_thumb, profile_picture_large, facebook_id", "users", "id = '{$_SESSION[user_id]}'"); list($profile_picture_thumb, $profile_picture_large, $facebook_id) = $sql-&gt;fetch_row(); $this-&gt;profile_picture_thumb = $profile_picture_thumb; $this-&gt;profile_picture_large = $profile_picture_large; $this-&gt;facebook_id = $facebook_id; if (local()) { $prepLocation = XAMPP; } else { $prepLocation = ''; } } </code></pre>
 

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