The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selecting and displaying data from a custom table
#1
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?
  Reply
#2
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.
  Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)