Hey guys,
I’m trying to pass a comma / or a , just before the variable genre_name in the script below
Can anyone please help me out?
$this->db->escape($data[‘genre_name’])
foreach ($data['product_description'] as $language_id => $value) {
$this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', description = '" . $this->db->escape($value['description']) . "', tag = '" . $this->db->escape($value['tag']) . $this->db->escape($data['genre_name']) . "', meta_title = '" . $this->db->escape($value['meta_title']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "'");
}
Are you using PDO? If not what database extension are you using?
So… ignoring for a moment that this is a behemoth of a query that really should be reorganized into a proper “VALUES” query, to insert a comma you… insert a comma, like all of the other hardcoded text in the line.
So you can see at the end there that the query inserts a comma by . concatenating a hardcoded string (denoted by doubel quotes). Just… add another one in the appropriate spot.
So you can see at the end there that the query inserts a comma by . concatenating a hardcoded string (denoted by doubel quotes). Just… add another one in the appropriate spot.
Don’t think that is possible as I want the comma between the [tag] and [genre_name]
This might work but have not tried it yet
"', tag = '" . $this->db->escape($value['tag']) . "','" $this->db->escape($data['genre_name']) . "',
Of course it can work. Maybe it will be so messy it isn’t easy to work with. (consider Heredoc syntax) but it can be done.
What you have is a series of String, Value, String, Value. … etc.
You might need to "“insert” the String between Values, but most doable.
I find that sacrificing a few bytes for readability’s sake is well worth it during work-up and maintenance. Compare.
foreach ($data['product_description'] as $language_id => $value) {
$this->db->query("INSERT INTO "
. DB_PREFIX
. "product_description SET product_id = '"
. (int)$product_id
. "', language_id = '"
. (int)$language_id
. "', name = '"
. $this->db->escape($value['name'])
. "', description = '"
. $this->db->escape($value['description'])
. "', tag = '"
. $this->db->escape($value['tag'])
. $this->db->escape($data['genre_name'])
. "', meta_title = '"
. $this->db->escape($value['meta_title'])
. "', meta_description = '"
. $this->db->escape($value['meta_description'])
. "', meta_keyword = '"
. $this->db->escape($value['meta_keyword'])
. "'");
Thanks for your replies.
Decided to approach this another way. Instead of trying to insert the Genre into the Product Tag I decided to add it to the Search Function.
This is what I did
SELECT ALL
$sql .= " OR LCASE(p.mpn) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";
add:
CODE: SELECT ALL
$sql .= " OR LCASE(p.genre_name) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";
system
Closed
November 11, 2015, 12:32pm
8
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.