Jump to content

bugzy

Members
  • Posts

    272
  • Joined

  • Last visited

Posts posted by bugzy

  1. I thought it would be simple but it seemed like it's complicated.

     

    I want to use the $_FILE twice so that I could have two copy of the image with different names..

     

    I'm doing it like this

     

    <?php
    
    
    //resizing image here
    
    $ext = ".". pathinfo($_FILES['uploaded_image']['name'], PATHINFO_EXTENSION);
    $target_path = "../images_item/";
    
    $filename1 = $target_path . $last_id."_medium".$ext;
    $filename2 = $target_path . $last_id."_large".$ext;
    
    
    $copied1 = move_uploaded_file($_FILES['uploaded_image']['tmp_name'], $filename1);
    
    $copied2 = move_uploaded_file($_FILES['uploaded_image']['tmp_name'], $filename2);
    
    
    ?>

     

     

    $_FILES is coming from an html form.

     

    Tried it but it only upload once..

     

    Any idea guys?  :shrug:

     

  2. I'm trying to resize an image on upload

     

    Here's the function

     

    <?php
    
    class SimpleImage {
    
       var $image;
       var $image_type;
    
    function me_resize($width,$height) {
    $new_image = imagecreatetruecolor($width, $height);
    if( $this->image_type == IMAGETYPE_GIF || $this->image_type == IMAGETYPE_PNG ) {
    	$current_transparent = imagecolortransparent($this->image);
    	if($current_transparent != -1) {
    		$transparent_color = imagecolorsforindex($this->image, $current_transparent);
    		$current_transparent = imagecolorallocate($new_image, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
    		imagefill($new_image, 0, 0, $current_transparent);
    		imagecolortransparent($new_image, $current_transparent);
    	} elseif( $this->image_type == IMAGETYPE_PNG) {
    		imagealphablending($new_image, false);
    		$color = imagecolorallocatealpha($new_image, 0, 0, 0, 127);
    		imagefill($new_image, 0, 0, $color);
    		imagesavealpha($new_image, true);
    	}
    }
    imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
    $this->image = $new_image;	
    }
    }
    
    ?>
    

     

     

    and I'm calling it like this

     

     

    <?php  $image = new SimpleImage();
      	 $image->load($_FILES['uploaded_image']['tmp_name']);
      	 $image->me_resize(250,400);
       	 $image->save($_FILES['uploaded_image']['tmp_name']); ?>

     

     

    and I'm getting this error

     

    Fatal error: Call to undefined method SimpleImage::load() in C:\wamp\www\runa\admin\add_item.php on line 48

     

     

    Any idea guys?  :shrug:

  3. Just a side question guys...

     

    Does imagecreatefromjpeg()  actually resize the original image on the server side, or it's being resize only on the end-user?

    imagecreatefromjpeg() doesn't do any resizing - it just converts a jpeg image to a GD image.

     

    From the word converting, so the original image will be a GD file now literally? and imagecreatefromjpeg() doesn't do any and image duplication? like the duplicate one will going to be the GD file? and the original will still be there as is? 

     

    Just want to be sure guys..

  4. I was researching on how will I able to resize an image on image retrieve and I got this function

     

    <?php
    
    function me_resize_jpeg( $original_image, $new_height, $new_width, $filename )
    {  
       // Resize the original image
       $image_resized = imagecreatetruecolor($new_width, $new_height);
       $image_tmp = imagecreatefromjpeg ($original_image);
       imagecopyresampled($image_resized, $image_tmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
       
       imagejpeg($image_resized, $filename.".jpg", 100);
       imagedestroy($image_resized);
    
    
    }
    
    
    ?>
    

     

    and I'm using it this way

     

    <?php
    
    $target_path = "../images_item/";
    
    me_resize_jpeg($target_path.$edit_id.".jpg",'100','50',$target_path.$edit_id);
    
    ?>
    

     

     

     

    But I'm getting this error:

     

    Undefined variable: width in C:\wamp\www\runa\includes\functions.php on line 58

     

    Undefined variable: height in C:\wamp\www\runa\includes\functions.php on line 58

     

     

    The function is only asking for four parameters and I don't if the function is missing something...

     

    Anyone?

  5. 		$ic_row[$c] = mysql_fetch_array($ic_result);
    
    //  ...
    
    			if(in_array(mysql_result($cat_result,$i,'cat_id'),$ic_row,TRUE))
    

     

    $ic_row is an array of arrays. You are searching for a scaler value; it will never be found.

     

    You probably meant to do $ic_row[$c] = mysql_result($ic_result, $c);

     

     

    This solves it.

     

    Thanks DavidAM!  :D

  6. What exactly are you trying to achieve? Your code is unnecessarily complex.

     

    Thorpe I have this merge table name "item_category" where all items' categories are stored. It's all stored using an html checkbox

     

    What I'm trying to do, If I want to edit an item category,  I'm want to retrieve those categories and check all the those that are listed as category in a checkbox.

     

    I'm trying to use "in_array" to store all the stored categories on an iteam.

     

    so it's like

     

    check all categories in_array(category1, category2) from table category using a forloop to display all categories.

     

     

    I wonder if this is possible using in_array?

  7. You should really be using a JOIN query.  MySQL is a relational database, and this is where it really shines.

    <?php
    $sql = "SELECT c.cat_id,c.cat_name,c.cat_visibility FROM category AS c JOIN item_category AS i ON i.category_id = c.cat_id WHERE i.item_id = $edit_id";
    $result = mysql_query($sql) or trigger_error($sql . ' has encountered an error.<br />' . mysql_error());
    if(mysql_num_rows($result) > 0) {
    while($row = mysql_fetch_assoc($result)) {
       echo "<input type=\"checkbox\" name=\"item_cat[]\" value=\"{$row['cat_id']}\" checked=\"checked\" /> {$row['cat_name']}<br />";
    }
    }
    

    If that throws an error, please post the code and the error(complete) back here.

     

    Hello..

     

    It only showing those checkboxes that are "checked" and not those who are also "unchecked"..

     

    ?

  8. 	
    <?php
    
    $ic = "Select category_id from item_category where item_id = {$edit_id}";
    	$ic_result = mysql_query($ic,$connection) or die (mysql_error());
    	$ic_num = mysql_num_rows($ic_result);
    
    
    	for($c = 0; $ic_num > $c; $c++)
    	{		
    	$ic_row[$c] = mysql_fetch_array($ic_result);
    	}
    
    
    for($i = 0; $cat_num > $i; $i++)
    	{
    
    			if(in_array(mysql_result($cat_result,$i,'cat_id'),$ic_row,TRUE))
    			{
    
    				echo "<input type=\"checkbox\" name=\"item_cat[]\" value=". mysql_result($cat_result,$i,'cat_id') . " checked=\"checked\" />"; 					echo mysql_result($cat_result,$i,'cat_name'). "<br>";
    
    			}
    			else
    			{
    				echo "<input type=\"checkbox\" name=\"item_cat[]\" value=". mysql_result($cat_result,$i,'cat_id') . " />"; 					
    				echo  mysql_result($cat_result,$i,'cat_name'). "<br>";
    
    			}
    
    }
    
    
    ?>

     

     

    It's bypassing the first condition and it goes straightly to the else condition...

     

    Anyone?

  9. Hello guys.. I have this loop

     

    <?php
    
    $cat_query = "Select cat_id, cat_name, cat_visibility from category where cat_id != 1 order by cat_position DESC";
    $cat_result = mysql_query($cat_query,$connection);
    $cat_num = mysql_num_rows($cat_result);
    
    $ic = "Select category_id from item_category where item_id = {$edit_id}";
    $ic_result = mysql_query($ic,$connection) or die (mysql_error());
    $ic_num = mysql_num_rows($ic_result);
    
    
    
    for($i = 0; $cat_num > $i; $i++)
    	{
    
    		for($c = 0; $ic_num > $c; $c++)
    		{
    			if(mysql_result($ic_result,$c,'category_id') == mysql_result($cat_result,$i,'cat_id'))
    			{
    
    				echo "<input type=\"checkbox\" name=\"item_cat[]\" value=". mysql_result($cat_result,$i,'cat_id') . " checked=\"checked\" />"; 					echo mysql_result($cat_result,$i,'cat_name'). "<br>";
    			}
    			else
    			{
    
    				echo "<input type=\"checkbox\" name=\"item_cat[]\" value=". mysql_result($cat_result,$i,'cat_id') . " />"; 					
    				echo  mysql_result($cat_result,$i,'cat_name'). "<br>";
    			}
    
    
    
    		}
    
    
    
    	}
    
    ?>
    

     

     

     

    the value I'm getting is being doubled like this

     

     

    ☑ category1

    ☐ category1

    ☐ category2

    ☐ category2

    ☑ category3

    ☐ category3

    ☐ category4

    ☐ category4

     

     

    I'm getting those categories that need to be check, problem is it doubles every value..

     

    Anyone?

  10. Newbie question guys..

     

    Just want to know the best approach on this before I code it.

     

    I have this merge table called "item_category" an item could have multiple rows base on how many categories the user chose.

     

    I have this on my mind...

     

    Delete all the item's rows(using item_ID PK)

    and then insert it again with the new one.

     

     

    So there's no update sql that will happen, only delete and insert...

     

    What do you think guys?

  11. Update item_category SET category_id=1 where item_id IN(166, 167)

     

    Thanks  jesirose. It's working though I'm having problem with ",";

     

    Here's the new code

     

    <?php
    
    		$query3 = "Update item_category SET category_id=1 where item_id IN (";
    
    		for($i=0;$i <= $row;$i++)
    		{
    			$get_id = mysql_result($result2, $i, 'Item');
    
    			if(mysql_result($result2,$i,'Total') == 1)
    			{				
    				$query3 .= "$get_id,";
    
    			}
    
    		}
    
    		$query3 .= ")";
    
    		$result3 = mysql_query(trim($query3,','),$connection);
    
    ?>

     

     

    It's giving me

     

    Update item_category SET category_id=1 where item_id IN (177,178,179,)

     

     

    How would I able to remove the comma on the last item_id?

  12. Hello guys base on my research seemed like I can't update multiple rows with different condition in one mysql query..

     

     

    Any idea guys how can I put this in just one single query?

     

    Update item_category

     

    SET category_id=1 where item_id = 166

    SET category_id=1 where item_id = 167

     

     

    I mean is there a work around?

  13.  

    for($i=0;$i <= $row;$i++)

    {

    $get_id[$i] = mysql_result($result2, $i, 'Item');

    if(mysql_result($result2,$i,'Total') == 1)

    {

     

    $query3 = mysql_query("Update item_category SET category_id='1' where item_id = '$get_id[$i]'");

     

    }// if

    }// for

     

     

    Again, as much as possible I don't want to put any sql query/statement inside a loop...

  14. If you're trying to validate that a field contains only the digits 0-9, you should be using ctype_digit, since is_numeric() will return TRUE for '0XABCDEF' (hexadecimal number) as well as 83.956e45 (exponential notation).

     

    Guys the problem is not is_numeric..

     

    "0" digit will always return true using the empty function of php. I have tried

     

    if != "";

     

    Not working also.. Any other good alternative for empty function??

  15. Newbie question guys...

     

     

    On my form

     

    <?php<input type="text" name="item_stock" size="3" value="<?php if(isset($_POST['submit']) AND is_numeric($_POST['item_stock'])) { echo $item_stock; } ?>

     

    I have this validation

     

    then

     

    <?php
    
    $item_stock = me_mysql_prep(trim($_POST['item_stock']));
    
    
    //validation
    
    if(!is_numeric($_POST['item_stock']) AND !empty($_POST['item_stock']))
    {
    	$item_sto = '';
    }
    else
    {
    	$item_sto = "has stock";
    }
    
    
    
    ?>

     

     

     

    On the validation, it keeps telling me that '0' is not numeric. I also tried using is_int.. but it's not working also..

     

    Anyone?

  16. The error might be useful?

     

    By that I mean the actual error message PHP gives you.

     

     

    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 2 on MySQL result index 17 in C:\wamp\www\runa\admin\delete_category.php on line 91

     

    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 2 on MySQL result index 17 in C:\wamp\www\runa\admin\delete_category.php on line 93

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET category_id=1 where item_id = 160' at line 1

     

     

    AGain, it only happened when I change the code from my above post.. Maybe I'm putting the first statement on the wrong way?

  17. The error might be useful?

     

     

    From this code

     

    <?php for($i=0;$i <= $row;$i++)
    		{
    			$get_id = mysql_result($result2, $i, 'Item');
    
    			if(mysql_result($result2,$i,'Total') == 1)
    			{				
    				$query3 = "Update item_category set category_id=1 where item_id = {$get_id}";
    				$result3 = mysql_query($query3,$connection) or die (mysql_error());
    			}
    
    		} ?>

     

     

     

    to this

     

     

     

    <?php
    
    $query3 = "Update item_category ";
    
    for($i=0;$i <= $row;$i++)
    
    {
    
    $get_id = mysql_result($result2, $i, 'Item');
    
    if(mysql_result($result2,$i,'Total') == 1)
    
    
    {
    
    $query3 .= "SET category_id=1 where item_id = {$get_id},";
    
    }
    
    
    }
    
    $result3 = mysql_query(trim($query3,','),$connection) or die (mysql_error());
    
    ?>
    
    
    

     

     

     

    I have change only the Update portion inside the for loop because I don't want to put a sql statement inside a loop, and I got an error already...

     

    Maybe I'm parsing it the wrong way or I place it on top of the loop which interfere it?

     

     

    Anyone?

  18. When I tried to parse it, the code suddenly is gibing me an error

     

    <?php
    
    $query3 = "Update item_category ";
    
    		for($i=0;$i <= $row;$i++)
    		{
    			$get_id = mysql_result($result2, $i, 'Item');
    
    			if(mysql_result($result2,$i,'Total') == 1)
    			{				
    				$query3 .= "SET category_id=1 where item_id = {$get_id},";
    
    			}
    
    		}
    
    
    
    		$result3 = mysql_query(trim($query3,','),$connection) or die (mysql_error());
    
    ?>

     

     

    I believe that I'm parsing the update statement the wrong way..

     

    Anyone?

×
×
  • 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.