Jump to content

lukelee

Members
  • Posts

    92
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

lukelee's Achievements

Member

Member (2/5)

0

Reputation

  1. ah, it works, thanks man. What if I want to display the articles before 7days? can I write :" between 7 AND 100000"
  2. Hi, Currently I am making a module for joomla. every article has an publish date, if the article was published in 7 days ago, it will displayed as "article in last week", My idea is to use today's date - publish date, if the result is greater than 7 and smaller than 14, the article will be displayed as "article in last week. Any one know how to write this code? Here is what I have got, but not working. <?php $todays_date = date("Y-m-d"); $result = mysql_query("select * from jos_content where $test between $todays_date-14 and $todays_date-7"); while($row = mysql_fetch_array($result)) { echo "$todays_date - $row[title]"; } ?>
  3. I want to search a product, there is 2 selects, first one is category, second one is sub category. when people select a category, the sub category under this category will come out. does anyone know how to do this? <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data"> <table border="0" class="catagory" > <tr><td><select name="firstlevel" style="width:180px;"> <option value="<?php echo $row['title']; ?>"><?php echo $row['title']; ?></option> </select></td> <td><select name="secondlevel" style="width:160px;"> <option value="<?php echo $row['sub_title']; ?>"><?php echo $row['sub_title']; ?></option> </select></td> <td><input type="submit" name="submit" id="submit" value="Submit" /></td> </tr> </table> </form>
  4. whats different between $password=$_POST['password']; and $password=$_POST[password]; seems both of them works. but which one is property?
  5. Hi, guys, I am making a simple shopping cart, now i got problem on check out function. i want to save the product information into database after click "checkout". because people may have different products in their shopping cart, so i made an array to display the items. but when I POST those items to next step which is check out, it only posts the latest item's information. can anyone help? thanks, here is a part of my code: function checkout() { $output[] = '<form action="checkout_process.php" method="post" id="cart">'; global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<table>'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM product WHERE product_id = '.$id; $result = $db->query($sql); $row = $result->fetch(); extract($row); $output[] = '<tr><td><input type="hidden" name="model" value="'.$model.'"/></td>'; $output[] = '<td><input type="hidden" name="quantity'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '<td><input type="hidden" name="price" value="'.$price.'"/></td>'; $output[] = '<td><input type="hidden" name="price" value="'.($price * $qty).'"/></td>'; $total += $price * $qty; $output[] = '</tr>'; } $output[] = '</table>'; $output[] = '<div><button type="submit">check out</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); }
  6. I am trying to code a simple shopping cart but I am just a php starter and I have no idea how to save and edit the product information (price, quantity...) in the session and show the visitors what they have added into the shopping cart? anyone have any ideas? any simple lines of code gonna help, thanks
  7. I have made it, I put $htmpage=$_SERVER['HTTP_REFERER']; at the top, then <meta HTTP-EQUIV="REFRESH" CONTENT="3;URL=<? echo $htmpage; ?>"> thanks guys
  8. no, it doesnt work, and also i dont understand what is $page = (!empty($_SESSION['gPage']))?$_SESSION['gPage']:"index.php"; why do we put index.php here?
  9. here is my code: <?php session_start(); session_destroy(); $Login=$_POST['Login']; if($Login){ $username=$_POST['username']; $password=$_POST['password']; require_once('db.php'); $result=mysql_query("select * from member where username='$username' and password='$password'"); if(mysql_num_rows($result)!='0'){ session_register("username"); header("index.php"); exit; }else{ echo "Wrong username and password, back in 3 sec!"; } } ?> <meta http-equiv="Refresh" content="3; URL=index.php" > if the user is invalid, go to index.php, but if the user is valid, go to the previous page, I have login from in every page, so is there any codes to let you go back 1 page?
  10. I want to make a function: after you login, it auto go back to the previous page, does anyone know how to write the code?
  11. there is no serious error actually, its just a "out of memory" when i upload a large size image, like 2mb.
  12. I have also tried to use only 1 class, but the same problem still occurs, whats the most common way to make a thumbnail? i feel my way is not correct.
  13. I am using same instance for 5 times because people could upload 5 images at once, if people choose the same file for all 5 images, lets say the image is imageA, imageA will be saved as 1 thumbnail, 1 original image. And i have another function called delete image, people could choose 1 of 5 images to delete, one of the image deleted, the rest of 4 images will be "cant display image", because they are sharing 1 thumbnail, 1 original image.
  14. Hi, can you take a look at my code, how to delete the images from memory? and refine my code, I have tried, but didnt work. sorry, i am a nub on php. <?php require_once('db.php'); $title1 = $_POST['title1']; $title2 = $_POST['title2']; $title3 = $_POST['title3']; $title4 = $_POST['title4']; $title5 = $_POST['title5']; $file1 = $_FILES['ufile1']['name']; $file2 = $_FILES['ufile2']['name']; $file3 = $_FILES['ufile3']['name']; $file4 = $_FILES['ufile4']['name']; $file5 = $_FILES['ufile5']['name']; $filesize1=$_FILES['ufile1']['size']; $filesize2=$_FILES['ufile2']['size']; $filesize3=$_FILES['ufile3']['size']; $filesize4=$_FILES['ufile4']['size']; $filesize5=$_FILES['ufile5']['size']; class resizeimage1 { var $type; var $width; var $height; var $resize_width; var $resize_height; var $cut; var $srcimg; var $dstimg; var $im; function resizeimage1($img, $wid, $hei,$c) { $this->srcimg = $img; $this->resize_width = $wid; $this->resize_height = $hei; $this->cut = $c; $this->type = substr(strrchr($this->srcimg,"."),1); $this->initi_img(); $this -> dst_img(); $this->width = imagesx($this->im); $this->height = imagesy($this->im); $this->newimg(); ImageDestroy ($this->im); } function newimg() { $resize_ratio = ($this->resize_width)/($this->resize_height); $ratio = ($this->width)/($this->height); if(($this->cut)=="1") { if($ratio>=$resize_ratio) { $newimg = imagecreatetruecolor($this->resize_width,$this->resize_height); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width,$this->resize_height, (($this->height)*$resize_ratio), $this->height); ImageJpeg ($newimg,$this->dstimg); echo " "; } if($ratio<$resize_ratio) { $newimg = imagecreatetruecolor($this->resize_width,$this->resize_height); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $this->width, (($this->width)/$resize_ratio)); ImageJpeg ($newimg,$this->dstimg); echo ""; } } else { if($ratio>=$resize_ratio) { $newimg = imagecreatetruecolor($this->resize_width,($this->resize_width)/$ratio); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, ($this->resize_width)/$ratio, $this->width, $this->height); ImageJpeg ($newimg,$this->dstimg); echo " "; } if($ratio<$resize_ratio) { $newimg = imagecreatetruecolor(($this->resize_height)*$ratio,$this->resize_height); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, ($this->resize_height)*$ratio, $this->resize_height, $this->width, $this->height); ImageJpeg ($newimg,$this->dstimg); echo " "; } } } function initi_img() { if($this->type=="jpg") { $this->im = imagecreatefromjpeg($this->srcimg); } if($this->type=="gif") { $this->im = imagecreatefromgif($this->srcimg); } if($this->type=="png") { $this->im = imagecreatefrompng($this->srcimg); } } function dst_img() { $full_length = strlen($this->srcimg); $type_length = strlen($this->type); $name_length = $full_length-$type_length; $name = substr($this->srcimg,0,$name_length-1); $this->dstimg = $name."_small.".$this->type; $new_small = basename($this->dstimg); } } class resizeimage2 { var $type; var $width; var $height; var $resize_width; var $resize_height; var $cut; var $srcimg; var $dstimg; var $im; function resizeimage2($img, $wid, $hei,$c) { $this->srcimg = $img; $this->resize_width = $wid; $this->resize_height = $hei; $this->cut = $c; $this->type = substr(strrchr($this->srcimg,"."),1); $this->initi_img(); $this -> dst_img(); $this->width = imagesx($this->im); $this->height = imagesy($this->im); $this->newimg(); ImageDestroy ($this->im); } function newimg() { $resize_ratio = ($this->resize_width)/($this->resize_height); $ratio = ($this->width)/($this->height); if(($this->cut)=="1") { if($ratio>=$resize_ratio) { $newimg = imagecreatetruecolor($this->resize_width,$this->resize_height); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width,$this->resize_height, (($this->height)*$resize_ratio), $this->height); ImageJpeg ($newimg,$this->dstimg); echo " "; } if($ratio<$resize_ratio) { $newimg = imagecreatetruecolor($this->resize_width,$this->resize_height); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $this->width, (($this->width)/$resize_ratio)); ImageJpeg ($newimg,$this->dstimg); echo ""; } } else { if($ratio>=$resize_ratio) { $newimg = imagecreatetruecolor($this->resize_width,($this->resize_width)/$ratio); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, ($this->resize_width)/$ratio, $this->width, $this->height); ImageJpeg ($newimg,$this->dstimg); echo " "; } if($ratio<$resize_ratio) { $newimg = imagecreatetruecolor(($this->resize_height)*$ratio,$this->resize_height); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, ($this->resize_height)*$ratio, $this->resize_height, $this->width, $this->height); ImageJpeg ($newimg,$this->dstimg); echo " "; } } } function initi_img() { if($this->type=="jpg") { $this->im = imagecreatefromjpeg($this->srcimg); } if($this->type=="gif") { $this->im = imagecreatefromgif($this->srcimg); } if($this->type=="png") { $this->im = imagecreatefrompng($this->srcimg); } } function dst_img() { $full_length = strlen($this->srcimg); $type_length = strlen($this->type); $name_length = $full_length-$type_length; $name = substr($this->srcimg,0,$name_length-1); $this->dstimg = $name."_small.".$this->type; $new_small = basename($this->dstimg); } } class resizeimage3 { var $type; var $width; var $height; var $resize_width; var $resize_height; var $cut; var $srcimg; var $dstimg; var $im; function resizeimage3($img, $wid, $hei,$c) { $this->srcimg = $img; $this->resize_width = $wid; $this->resize_height = $hei; $this->cut = $c; $this->type = substr(strrchr($this->srcimg,"."),1); $this->initi_img(); $this -> dst_img(); $this->width = imagesx($this->im); $this->height = imagesy($this->im); $this->newimg(); ImageDestroy ($this->im); } function newimg() { $resize_ratio = ($this->resize_width)/($this->resize_height); $ratio = ($this->width)/($this->height); if(($this->cut)=="1") { if($ratio>=$resize_ratio) { $newimg = imagecreatetruecolor($this->resize_width,$this->resize_height); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width,$this->resize_height, (($this->height)*$resize_ratio), $this->height); ImageJpeg ($newimg,$this->dstimg); echo " "; } if($ratio<$resize_ratio) { $newimg = imagecreatetruecolor($this->resize_width,$this->resize_height); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $this->width, (($this->width)/$resize_ratio)); ImageJpeg ($newimg,$this->dstimg); echo ""; } } else { if($ratio>=$resize_ratio) { $newimg = imagecreatetruecolor($this->resize_width,($this->resize_width)/$ratio); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, ($this->resize_width)/$ratio, $this->width, $this->height); ImageJpeg ($newimg,$this->dstimg); echo " "; } if($ratio<$resize_ratio) { $newimg = imagecreatetruecolor(($this->resize_height)*$ratio,$this->resize_height); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, ($this->resize_height)*$ratio, $this->resize_height, $this->width, $this->height); ImageJpeg ($newimg,$this->dstimg); echo " "; } } } function initi_img() { if($this->type=="jpg") { $this->im = imagecreatefromjpeg($this->srcimg); } if($this->type=="gif") { $this->im = imagecreatefromgif($this->srcimg); } if($this->type=="png") { $this->im = imagecreatefrompng($this->srcimg); } } function dst_img() { $full_length = strlen($this->srcimg); $type_length = strlen($this->type); $name_length = $full_length-$type_length; $name = substr($this->srcimg,0,$name_length-1); $this->dstimg = $name."_small.".$this->type; $new_small = basename($this->dstimg); } } class resizeimage4 { var $type; var $width; var $height; var $resize_width; var $resize_height; var $cut; var $srcimg; var $dstimg; var $im; function resizeimage4($img, $wid, $hei,$c) { $this->srcimg = $img; $this->resize_width = $wid; $this->resize_height = $hei; $this->cut = $c; $this->type = substr(strrchr($this->srcimg,"."),1); $this->initi_img(); $this -> dst_img(); $this->width = imagesx($this->im); $this->height = imagesy($this->im); $this->newimg(); ImageDestroy ($this->im); } function newimg() { $resize_ratio = ($this->resize_width)/($this->resize_height); $ratio = ($this->width)/($this->height); if(($this->cut)=="1") { if($ratio>=$resize_ratio) { $newimg = imagecreatetruecolor($this->resize_width,$this->resize_height); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width,$this->resize_height, (($this->height)*$resize_ratio), $this->height); ImageJpeg ($newimg,$this->dstimg); echo " "; } if($ratio<$resize_ratio) { $newimg = imagecreatetruecolor($this->resize_width,$this->resize_height); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $this->width, (($this->width)/$resize_ratio)); ImageJpeg ($newimg,$this->dstimg); echo ""; } } else { if($ratio>=$resize_ratio) { $newimg = imagecreatetruecolor($this->resize_width,($this->resize_width)/$ratio); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, ($this->resize_width)/$ratio, $this->width, $this->height); ImageJpeg ($newimg,$this->dstimg); echo " "; } if($ratio<$resize_ratio) { $newimg = imagecreatetruecolor(($this->resize_height)*$ratio,$this->resize_height); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, ($this->resize_height)*$ratio, $this->resize_height, $this->width, $this->height); ImageJpeg ($newimg,$this->dstimg); echo " "; } } } function initi_img() { if($this->type=="jpg") { $this->im = imagecreatefromjpeg($this->srcimg); } if($this->type=="gif") { $this->im = imagecreatefromgif($this->srcimg); } if($this->type=="png") { $this->im = imagecreatefrompng($this->srcimg); } } function dst_img() { $full_length = strlen($this->srcimg); $type_length = strlen($this->type); $name_length = $full_length-$type_length; $name = substr($this->srcimg,0,$name_length-1); $this->dstimg = $name."_small.".$this->type; $new_small = basename($this->dstimg); } } class resizeimage5 { var $type; var $width; var $height; var $resize_width; var $resize_height; var $cut; var $srcimg; var $dstimg; var $im; function resizeimage5($img, $wid, $hei,$c) { $this->srcimg = $img; $this->resize_width = $wid; $this->resize_height = $hei; $this->cut = $c; $this->type = substr(strrchr($this->srcimg,"."),1); $this->initi_img(); $this -> dst_img(); $this->width = imagesx($this->im); $this->height = imagesy($this->im); $this->newimg(); ImageDestroy ($this->im); } function newimg() { $resize_ratio = ($this->resize_width)/($this->resize_height); $ratio = ($this->width)/($this->height); if(($this->cut)=="1") { if($ratio>=$resize_ratio) { $newimg = imagecreatetruecolor($this->resize_width,$this->resize_height); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width,$this->resize_height, (($this->height)*$resize_ratio), $this->height); ImageJpeg ($newimg,$this->dstimg); echo " "; } if($ratio<$resize_ratio) { $newimg = imagecreatetruecolor($this->resize_width,$this->resize_height); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $this->width, (($this->width)/$resize_ratio)); ImageJpeg ($newimg,$this->dstimg); echo ""; } } else { if($ratio>=$resize_ratio) { $newimg = imagecreatetruecolor($this->resize_width,($this->resize_width)/$ratio); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, ($this->resize_width)/$ratio, $this->width, $this->height); ImageJpeg ($newimg,$this->dstimg); echo " "; } if($ratio<$resize_ratio) { $newimg = imagecreatetruecolor(($this->resize_height)*$ratio,$this->resize_height); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, ($this->resize_height)*$ratio, $this->resize_height, $this->width, $this->height); ImageJpeg ($newimg,$this->dstimg); echo " "; } } } function initi_img() { if($this->type=="jpg") { $this->im = imagecreatefromjpeg($this->srcimg); } if($this->type=="gif") { $this->im = imagecreatefromgif($this->srcimg); } if($this->type=="png") { $this->im = imagecreatefrompng($this->srcimg); } } function dst_img() { $full_length = strlen($this->srcimg); $type_length = strlen($this->type); $name_length = $full_length-$type_length; $name = substr($this->srcimg,0,$name_length-1); $this->dstimg = $name."_small.".$this->type; $new_small = basename($this->dstimg); } } $tempimgname1 = strtolower($_FILES["ufile1"][name]); $tempimgname1 = mb_convert_encoding( $tempimgname1, "gb2312", "utf-8"); $filesize1=$_FILES['ufile1']['size']; $tempimgname2 = strtolower($_FILES["ufile2"][name]); $tempimgname2 = mb_convert_encoding( $tempimgname2, "gb2312", "utf-8"); $filesize2=$_FILES['ufile2']['size']; $tempimgname3 = strtolower($_FILES["ufile3"][name]); $tempimgname3 = mb_convert_encoding( $tempimgname3, "gb2312", "utf-8"); $filesize3=$_FILES['ufile3']['size']; $tempimgname4 = strtolower($_FILES["ufile4"][name]); $tempimgname4 = mb_convert_encoding( $tempimgname4, "gb2312", "utf-8"); $filesize4=$_FILES['ufile4']['size']; $tempimgname5 = strtolower($_FILES["ufile5"][name]); $tempimgname5 = mb_convert_encoding( $tempimgname5, "gb2312", "utf-8"); $filesize5=$_FILES['ufile5']['size']; if($filesize1>0) { if(copy($_FILES["ufile1"]["tmp_name"],strtolower("gallery/".date("Y-m-d-h-m-s",time()).$tempimgname1))){ $image1 = basename(strtolower("gallery/".date("Y-m-d-h-m-s",time()).$tempimgname1)); $class1 = new resizeimage1("gallery/".date("Y-m-d-h-m-s",time()).$tempimgname1, 110, 110, 1); $s_image1 = basename($class1->dstimg); $query = mysql_query("INSERT INTO gallary(title, thumb, imagedata) VALUES ('$title1','$s_image1','$image1')"); imagedestroy($_FILES["ufile1"]["tmp_name"]); } } if($filesize2>0) { if(copy($_FILES["ufile2"]["tmp_name"],strtolower("gallery/".date("Y-m-d-h-m-s",time()).$tempimgname2))){ $image2 = basename(strtolower("gallery/".date("Y-m-d-h-m-s",time()).$tempimgname2)); $class2 = new resizeimage2("gallery/".date("Y-m-d-h-m-s",time()).$tempimgname2, 110, 110, 1); $s_image2 = basename($class2->dstimg); $query = mysql_query("INSERT INTO gallary(title, thumb, imagedata) VALUES ('$title2','$s_image2','$image2')"); imagedestroy($_FILES["ufile2"]["tmp_name"]); } } if($filesize3>0) { if(copy($_FILES["ufile3"]["tmp_name"],strtolower("gallery/".date("Y-m-d-h-m-s",time()).$tempimgname3))){ $image3 = basename(strtolower("gallery/".date("Y-m-d-h-m-s",time()).$tempimgname3)); $class3 = new resizeimage3("gallery/".date("Y-m-d-h-m-s",time()).$tempimgname3, 110, 110, 1); $s_image3 = basename($class3->dstimg); $query = mysql_query("INSERT INTO gallary(title, thumb, imagedata) VALUES ('$title3','$s_image3','$image3')"); imagedestroy($_FILES["ufile3"]["tmp_name"]); } } if($filesize4>0) { if(copy($_FILES["ufile4"]["tmp_name"],strtolower("gallery/".date("Y-m-d-h-m-s",time()).$tempimgname4))){ $image4 = basename(strtolower("gallery/".date("Y-m-d-h-m-s",time()).$tempimgname4)); $class4 = new resizeimage4("gallery/".date("Y-m-d-h-m-s",time()).$tempimgname4, 110, 110, 1); $s_image4 = basename($class4->dstimg); $query = mysql_query("INSERT INTO gallary(title, thumb, imagedata) VALUES ('$title4','$s_image4','$image4')"); imagedestroy($_FILES["ufile4"]["tmp_name"]); } } if($filesize5>0) { if(copy($_FILES["ufile5"]["tmp_name"],strtolower("gallery/".date("Y-m-d-h-m-s",time()).$tempimgname5))){ $image5 = basename(strtolower("gallery/".date("Y-m-d-h-m-s",time()).$tempimgname5)); $class5 = new resizeimage5("gallery/".date("Y-m-d-h-m-s",time()).$tempimgname5, 110, 110, 1); $s_image5 = basename($class5->dstimg); $query = mysql_query("INSERT INTO gallary(title, thumb, imagedata) VALUES ('$title5','$s_image5','$image5')"); imagedestroy($_FILES["ufile5"]["tmp_name"]); } } else { echo "You didn't pick any images." ; } ?>
×
×
  • 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.