Help with php update and delete function.

Discussion in 'PHP' started by lowridertj, Nov 9, 2007.

  1. #1
    Currently there is a feature to update each individual item that is in my database.

    Example:
    //print_r($_POST);
    		if($approve!='')
    		{
    		 //echo "test";
    $rsscat=$_POST['rsscat'];
    //echo $rsscat;
    $id=$_POST['id'];
    $name=$_POST['feedname'];
    $str="SELECT * from `temp_links` where `id` = '$id'";
    $temp=$F($Q($str));
    			$approved_str="INSERT INTO `pron_links` VALUES ('".$temp["id"]."','".$temp["user"]."','".$rsscat."','".$name."','".$temp["desc"]."','".$temp["picture"]."','".$temp["link"]."','".$temp["visited"]."','".$temp["date"]."','".$temp["time"]."','1','".$temp["rate_points"]."','".$temp["iframe_rate"]."','".$temp["percent"]."')";
    			$Q($approved_str);
    	$str_delete="DELETE FROM `temp_links` WHERE `id`='$id'";
    			$Q($str_delete);
    //			echo "<script> window.location='templinks.php?approved=1'; <script>";
    
    		}
    PHP:

    What I want to do is call it so that it takes all items in the

    $str="SELECT * from `temp_links` where `id` = '$id'";
    PHP:
    area and insert them all with 1 click to the

    $approved_str="INSERT INTO `pron_links` VALUES ('".$temp["id"]."','".$temp["user"]."','".$rsscat."','".$name."','".$temp["desc"]."','".$temp["picture"]."','".$temp["link"]."','".$temp["visited"]."','".$temp["date"]."','".$temp["time"]."','1','".$temp["rate_points"]."','".$temp["iframe_rate"]."','".$temp["percent"]."')";
    			$Q($approved_str);
    PHP:
    and delete from

    $str_delete="DELETE FROM `temp_links` WHERE `id`='$id'";
    			$Q($str_delete);
    PHP:

    Can someone please help me with this. Would be greatly appreciated.

    Thanks,
    TJ
     
    lowridertj, Nov 9, 2007 IP
  2. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #2
    $str="SELECT * from `temp_links` where `id` = '$id'";
    $rs = mysql_query($str);
    if(mysql_num_rows($rs)){
    	while($temp = mysql_fetch_array($rs)){
    		$approved_str=mysql_query("INSERT INTO `pron_links` VALUES '".$temp["id"]."','".$temp["user"].")");
    		$str_delete=mysql_query("DELETE FROM `temp_links` WHERE `id`='$id'");
    	}	
    }
    PHP:
    Is this what you want
     
    greatlogix, Nov 9, 2007 IP
  3. lowridertj

    lowridertj Well-Known Member

    Messages:
    2,882
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    195
    #3
    not exactly.

    From the above statement.

    
    //print_r($_POST);
            if($approve!='')
            {
             //echo "test";
    $rsscat=$_POST['rsscat'];
    //echo $rsscat;
    $id=$_POST['id'];
    $name=$_POST['feedname'];
    $str="SELECT * from `temp_links` where `id` = '$id'";
    $temp=$F($Q($str));
                $approved_str="INSERT INTO `pron_links` VALUES ('".$temp["id"]."','".$temp["user"]."','".$rsscat."','".$name."','".$temp["desc"]."','".$temp["picture"]."','".$temp["link"]."','".$temp["visited"]."','".$temp["date"]."','".$temp["time"]."','1','".$temp["rate_points"]."','".$temp["iframe_rate"]."','".$temp["percent"]."')";
                $Q($approved_str);
        $str_delete="DELETE FROM `temp_links` WHERE `id`='$id'";
                $Q($str_delete);
    //      echo "<script> window.location='templinks.php?approved=1'; <script>";
    
            }
    
    PHP:
    What that does right now is when i click to submit that link it updates only that link id into the new table.

    What I want to do is have it setup that it inserts all of them over to the new table then deletes them from the old table.

    Temp table they rest in they are called from

    $str="SELECT * from `temp_links` where `id` = '$id'";
    PHP:
    and inserted 1 at a time when i click to approve it to

    $approved_str="INSERT INTO `pron_links` VALUES ('".$temp["id"]."','".$temp["user"]."','".$rsscat."','".$name."','".$temp["desc"]."','".$temp["picture"]."','".$temp["link"]."','".$temp["visited"]."','".$temp["date"]."','".$temp["time"]."','1','".$temp["rate_points"]."','".$temp["iframe_rate"]."','".$temp["percent"]."')";
                $Q($approved_str);
    PHP:
    then deletes it.


    However I want to set it up that when it calls the temp table it gets all id > 0

    and inserts them all to the new table

    $approved_str="INSERT INTO `pron_links` VALUES ('".$temp["id"]."','".$temp["user"]."','".$rsscat."','".$name."','".$temp["desc"]."','".$temp["picture"]."','".$temp["link"]."','".$temp["visited"]."','".$temp["date"]."','".$temp["time"]."','1','".$temp["rate_points"]."','".$temp["iframe_rate"]."','".$temp["percent"]."')";
                $Q($approved_str);
    PHP:
    then deletes them all from the previous table there were in.



    Hopefully i didn't lose you with this.
     
    lowridertj, Nov 9, 2007 IP