Search Posts

How to Combine text and query result as value of a PHP variable

I have a variable ($html) which has some value assigned to it (Later I need to save it as PDF with MPDF). A part of it’s value is generated by making query to database.
Right now the code looks like…

$html = '

           <td>ITEM NAME</td>


        $items_query = "SELECT * FROM cart WHERE u_id='$u_id'"
        or die('Error Querying Database...');

        $run_items_query = mysqli_query($con, $items_query);

        while($row_query = mysqli_fetch_array($run_items_query)){

            $item = $row_query['p_name'];
            $unit_price = $row_query['price'];
            $qty = $row_query['qty'];
            $price = $unit_price*$qty;



What I am doing here is – Creating simple table and adding all the <td> via SQL Query. I can’t get how to concatenate simple text part and query result part as value to the $html variable.
Right now it shows only the first part of the value before query start and then shows this – ‘SELECT * FROM cart WHERE u_id=’ee0fivtt9tq39i5mpdhtf9v051’ … not the <td> that it gets.
Please let me know if you can figure out what I am doing wrong…

Source: Stackoverflow

Leave a Reply

Your email address will not be published. Required fields are marked *