1

I'm trying to do some MYSQL Concat with PHP script because I like to add a PHP conditions on it but it's not working.

'concat("<input type=\"checkbox\" value=\"", sup.sup_id, "" "\" name=\"supplier_id[]\" <?=(in_array(\", sup.sup_id,"" "\", $suppliers) ? \"checked\" : \"\") ?> >") AS Select"');

The checkbox without the PHP script is working properly, but when I added the script,the script is not working. And the checkbox is displaying > beside it.

I think I'm having trouble closing the script, what is the correct way to make this working??

EDIT

Here are some details

$select = array('sup.sup_name AS "Company Name"','suppro.suppro_price AS "Price"',
            'concat("<input type=\"checkbox\" value=\"", sup.sup_id,"" "\" name=\"supplier_id[]\" <?=(in_array(\"", sup.sup_id,"" "\",$suppliers) ? \"checked\" : \"\") ?> >") AS "Select"');
        $where = array('prod.pro_id' => $item_id);

        $result = $this->canvas->getItemCanvas($select, $where, 'crts_products prod');
        $actions = array();
        $total_rows = 0;

        $this->_data['suppliers']       = $suppliers;

        $this->_data['flashsuccess']    = $this->session->flashdata('msg');
        $this->_data['pr_id']           = $pr_id;
        $this->_data['item_id']         = $item_id;
        $this->_data['qty']             = $qty;
        $this->_data['header']          = 'Canvas Company for Item<br><small>'.$item_name.' QTY: '.$qty.'</small>';
        $this->_data['listing']         = table_listing('user',$result, $total_rows,$offset, $this->_limit, $actions, 3, false,'','');
        $this->_data['form_url']        = user_url().'canvas/save_canvas/';
        $this->set_template('user/canvas/begin',$this->_data, 'user');

Here's the working screenshot enter image description here But when I added the PHP script inside concat, here's what it looks like enter image description here

6
  • What does this output as in your browser? and/or can you show the PHP outputting of this?
    – chris85
    Dec 1, 2015 at 3:50
  • why you going for concat?can you post some more details or code. Dec 1, 2015 at 3:54
  • 1
    You are attempting to output php code in the concatenated string? Ie that you hope will be processed by php?
    – Tristan
    Dec 1, 2015 at 3:55
  • I see 2 times where you have "" "\" in the string. the first time is in "" "\" name=\" in which 2 double quotes which appear aren't being escaped. the second time is sup.sup_id,"" "\",, likewise 2 sets of double quotes appear aren't being escaped. though i would have to question why you are using MySQL to concat PHP/HTML code because i can't see your in_array PHP working to my knowledge since it's now a string you have to echo out
    – Memor-X
    Dec 1, 2015 at 4:07
  • 1
    You need to use eval() to execute the php code in the string otherwise it will be echoed to the browser as a string - which is what appears to be happening.
    – Tristan
    Dec 1, 2015 at 4:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.