Jump to content

Barand

Moderators
  • Posts

    24,361
  • Joined

  • Last visited

  • Days Won

    798

Posts posted by Barand

  1. What a waste of effort.

    Try

    $servername = "mysql.woodjoint.com";
    $username = "MyUsername";
    $password = "MyPassword";
    $db = "woodjoint";
    
    mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
    $conn = mysqli_connect($servername, $username, $password, $db);
       
       $sql = 'SELECT title
                    , venue
                    , address
               FROM shows';
       $result = $conn->query($sql);
       
       foreach ($result as $row) {
           echo "Title :{$row['Title']}  <br> ".
               "Venue : {$row['Venue']} <br> ".
               "Address : {$row['Address']} <br> ".
               "--------------------------------<br>";
       }

    Specify the fields you need in the SELECT, not "*".

    You specified the default db when you connected so no need to select the db again.

    With a mysqli result object (but not with a statement object if you  used a prepared query) you can simply use foreach() to loop through the results.

    My advice is to switch to PDO for future projects.

  2. perhaps

    select 
    	i.name as itemName,
    	qs.name as sectionName,
    	i.id as itemId,
    	i.GBP,
    	i.USD,
    	i.CAD,
    	cb.charge_by,
        COUNT(cp.item_id) > 0 as icConsumable
    from items i
        inner join quote_sections qs on i.section_id=qs.id
        inner join charge_by cb on i.charge_by_id = cb.id
        left join consumable_price cp ON i.id = cp.item_id
    group by i.id
    union 
    select 
    	ci.name as itemName,
    	qs.name as sectionName,
    	concat("CI", ci.id) as itemId,
    	ci.price as GBP,
    	ci.price as USD,
    	ci.price as CAD,
    	cb.charge_by,
        0 as isConsumable
    from custom_item ci
    inner join quote_sections qs on ci.section_id=qs.id
    inner join charge_by cb on ci.charge_by = cb.id

     

  3. Do you want to show

    • all items with indication that it is in consumables, or
    • only items where there is a consumables record, or
    • only items with no consumables records

    (I have to ask as you have not given an example where you used the table)

  4. LEFT JOIN (
              SELECT item_id, COUNT(*) as tot
              FROM consumables 
              GROUP BY item_id
              ) con USING (item_id)

    If you use a subquery like the above, instead of joining directly to the table, it will eliminate the duplicate rows.

  5. Give us some context - that tells us nothing.

    What is the name of that table and what is the query giving the problem?

    EDIT: Note - you need a join on item_id AND  qty BETWEEN min AND max

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.