// Query database for the articles of a category if (!$subcatid || $subcatid == '') return FALSE; $sqlstr = "select * from er_tblarticles where subcatid='$subcatid'"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); if ($num == 0) return FALSE; for ($count = 0; $row=mysql_fetch_assoc($res); $count++) $res_array[$count] = $row; return $res_array; } function get_cgi_param ($feld, $default) { $var = $default; $rmeth = $_SERVER['REQUEST_METHOD']; if ($rmeth == "GET") { if (isset ($_GET[$feld]) && $_GET[$feld] != "") { $var = $_GET[$feld]; } } elseif ($rmeth == "POST") { if (isset ($_POST[$feld]) && $_POST[$feld] != "") { $var = $_POST[$feld]; } } return $var; } // Adjust picture function resize($file, $save, $width, $height=false) { if(!$height) $height = $width; $infos = @getimagesize($file); $iWidth = $infos[0]; $iHeight = $infos[1]; $iRatioW = $width / $iWidth; $iRatioH = $height / $iHeight; if($iRatioW < $iRatioH) { $iNewW = $iWidth * $iRatioW; $iNewH = $iHeight * $iRatioW; } else { $iNewW = $iWidth * $iRatioH; $iNewH = $iHeight * $iRatioH; } // if if($infos[2] == 1) $imgA = @imagecreatefromgif($file); elseif($infos[2] == 2) $imgA = @imagecreatefromjpeg($file); elseif($infos[2] == 3) $imgA = @imagecreatefrompng($file); $imgB = @imagecreatetruecolor($iNewW, $iNewH); if(!$imgB) $imgB = @imagecreate($iNewW, $iNewH); if(!@imagecopyresampled($imgB, $imgA, 0, 0, 0, 0, $iNewW, $iNewH, $infos[0], $infos[1])) @imagecopyresized($imgB, $imgA, 0, 0, 0, 0, $iNewW, $iNewH, $infos[0], $infos[1]); $re = null; umask(0777); if($infos[2] == 1) $re = imagegif($imgB, $save); elseif($infos[2] == 2) $re = imagejpeg($imgB, $save, 100); else $re = imagepng($imgB, $save); return true; } // New added function get_articlesdetails($id) { if (!$id || $id == '') return FALSE; $conn = db_connect(); $sqlstr = "select * from er_tblarticles where id='$id'"; $res = @$conn->query($sqlstr); if (!$res) return FALSE; $res = @$res->fetch_assoc(); return $res; } function calculate_price($cart) { // Calculate the total price for all items in the shopping cart $price = 0.0; if (is_array($cart)) { $conn = db_connect(); foreach($cart as $id => $qty) { $sqlstr = "select price from er_tblarticles where id='$id'"; $res = $conn->query($sqlstr); if ($res) { $item = $res->fetch_object(); $item_price = $item->price; $price += $item_price * $qty; } } } return $price; } function calculate_items($cart) { // Calculate the number of items in your cart $items = 0; if (is_array($cart)) { foreach($cart as $id => $qty) { $items += $qty; } } return $items; } ?>Shop by Mehdi Bandegani