The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/printthread.php 16 require_once



UserSpice
Selecting and displaying data from a custom table - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28)
+--- Forum: Modifications and Hackery (https://userspice.com/forums/forumdisplay.php?fid=29)
+--- Thread: Selecting and displaying data from a custom table (/showthread.php?tid=307)



Selecting and displaying data from a custom table - Dan.ETD - 10-10-2016

I have created a custom table in my database holding colour codes for distributors of my products.

I am trying to echo out the header and footer column using the following statement:
$db = DB::getInstance();
$customiseQ = $db->query("SELECT * FROM customise-distributor WHERE distributor = ". $parts[4] ."");
$customise = $customiseQ->first();

echo "Header Colour: ". $customise->header_colour ."";

Why is $customise->header_colour blank?


Selecting and displaying data from a custom table - mudmin - 10-10-2016

Whenever you're passing a variable into a raw sql query, you should bind your variable. Also, if you're using the header from userspice on your page, you don't have to do the DB::getInstance because the header instantiates the db for you.

Ok. So here is how I would write that....

$customiseQ = $db->query(“SELECT * FROM customise-distributor WHERE distributor = ?",array($parts[4]); //bind your variable.

Personally, when I'm trying to echo that stuff out, I close php and go back to html...

So I would do
Header Colour:<?=$customise->header_colour?>

I hope that helps. You can also do
dump($customize);
to see everything your query brought back to make sure there isn't a misspelling or something.