php - How to fetch all data from 2 tables and display all not working -


i'm trying fetch data items table , inventory table , display information. problem i'm having displayed right except displays whats in inventory table, , display items items table , quantity inventory table. how correctly here code

$result= mysqli_query($link, "select * items left outer join inventory on inventory.itemid=items.id inventory.userid = '".$userid."'");   while($row = mysqli_fetch_array($result) ) {        if ($row['type'] == 0 && $row['level'] > 0){         $item .= "          <td width='200px'>             <form action='gear.php' method='post'>                 <div class='featured_items'><img src='". $row['image']."' width='80' height='80' style='border: 1px solid #333'></div>                 <div class='featured_items_info'>". $row['itemname'] ." <br />                     att ". $row['attack'] ."                     | def ". $row['defense'] ."<br />                     cost ". $row['cost'] ."<br />                     own ". $row['quantity'] ."<br />                    <input type='hidden' name='gear_id' value='". $row['id'] ."' />                 <input type='submit' value='buy' />             </form>          </td>          ";      }    } 

the left join didn't work way intended because used user_id field, belonged inventory. moving condition on fix it:

select id, type, level, image, itemname, attack, defense,      cost, coalesce(inventory.quantity, 0) quantity items  left outer join inventory on inventory.itemid=items.id , inventory.userid = '".$userid."'" 

just make sure use coalesce in select handle items user doesn't have.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -