} public static function get_all_size() { global $database; $sql = "SELECT * FROM size"; $result = $database->query($sql); return $result; } public function insert_this_object() { global $database; $sql = "INSERT INTO itemsize VALUES({$this->ItemId}\n ,{$this->SizeId}\n ,{$this->Count}\n ,{$this->ColorId});"; $database->query($sql); } public function get_element_by_id($id) { global $database; $sql = "SELECT * FROM itemSize WHERE ItemId="; $sql .= $id; return $database->query($sql); while ($row = mysqli_fetch_array($result)) { foreach ($row as $cname => $cvalue) { print "{$cname}:{$cvalue}"; } echo "</br>"; } } } $item = new ItemSize(); $item->get_element_by_id(28);
private static function item_formating($all_rows) { $itemSize = new ItemSize(); $colors = array(); $result = $itemSize->get_all_colors(); while ($row = mysqli_fetch_array($result)) { $colors[$row['Id']] = $row['Name']; } $sizes = array(); $result = $itemSize->get_all_size(); while ($row = mysqli_fetch_array($result)) { $sizes[$row['Id']] = $row['Number']; } while ($row = mysqli_fetch_array($all_rows)) { $quantity = 0; $result = $itemSize->get_element_by_id($row['Id']); while ($row1 = mysqli_fetch_array($result)) { $quantity += $row1['Quantity']; } if ($quantity > 0) { //echo "dude"; $img = $row['Image']; echo "<div value=" . $row['Id'] . " class='item'>"; echo "<img src='{$img}'" . "alt=" . $row['Name'] . ">"; echo "<div class='itemInfo'>"; echo "<table id='info'>"; echo "<tr>"; echo "<td>Price:<spin class='price'>" . $row['Price'] . "\$</spin></td>"; echo "<td>Size"; $result = $itemSize->get_element_by_id($row['Id']); echo "<select onchange='colorsToSize(this)'>"; echo "<option selected disabled hidden value=''></option>"; while ($row2 = mysqli_fetch_array($result)) { if ($row2['Quantity'] != 0) { print "<option value='" . $row2['SizeId'] . "'>" . $sizes[$row2['SizeId']] . "</option>"; } } echo "</select>"; echo "<td>Color"; $result = $itemSize->get_element_by_id($row['Id']); echo "<select class='colors'>"; echo "<option selected disabled hidden value=''></option>"; while ($row1 = mysqli_fetch_array($result)) { if ($row1['Quantity'] != 0) { print "<option display='none' class='" . $row1['SizeId'] . "'value='" . $row1['ColorId'] . "' style='background-color:" . $colors[$row1['ColorId']] . "; color:" . $colors[$row1['ColorId']] . "'>" . $colors[$row1['ColorId']] . "</option>"; } } echo "</select>"; echo "</tr>"; echo "</td>"; echo "</table>"; echo "<button type='submit' onclick='addRow(this)'>Add Item</button>"; echo "</div>"; echo "</div>"; } } }