Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    74
    Thanks
    2
    Thanked 0 Times in 0 Posts

    How funny it is in PHP. i hate it

    Please read this thread carefully. you need a few minutes to read it--

    i wrote a script like this ::

    PHP Code:

    $rowDetailofBackupCategory
    =mysql_fetch_assoc(mysql_query("SELECT * FROM category_backup WHERE category_id='$categoryId'"));

     
    $categoryName=$rowDetailofBackupCategory['category_name'];
             
    $categoryDescription=$rowDetailofBackupCategory['category_description'];
             
    $categoryThumbImage=$rowDetailofBackupCategory['category_thumb_image'];
             
    $categoryFullImage=$rowDetailofBackupCategory['category_full_image'];
    $mdate=$rowDetailofBackupCategory['mdate'];
    $isBrand=$rowDetailofBackupCategory['IsBrand'];
             
    $categoryFromDate=$rowDetailofBackupCategory['category_from_date'];
             
    $categoryUptoDate=$rowDetailofBackupCategory['category_upto_date'];




    /*
    Retriving data from category_backup i need to update category table so i wrote like --
    */
     
    $approvedEditSql="UPDATE category SET
                                        category_name='$categoryName',
                                        category_description='$categoryDescription',
                                        category_thumb_image='$categoryThumbImage',
                                        category_full_image='$categoryFullImage',
                                        mdate='$mdate',
                                        IsBrand='$isBrand',
                                        category_from_date='$categoryFromDate',
                                        category_upto_date='$categoryUptoDate',
                                        category_publish='Y'
                                        WHERE category_id='$categoryId'"
    ;


     
    mysql_query($approvedEditSql) or die("problem hoche"); 
    but in category table only category_publish is updated which value is "Y" and it is a constant value not retrieved from category_backup.no other value is but the rest of field is not updated rather their values are changed to default values.

    though i printed all the variable which is found from category_backup is looking ok.(thea is i m getting the value)

    When i re write the above code is like that--



    PHP Code:
     $resultOfBackupData=mysql_query("SELECT * FROM category_backup WHERE category_id='$categoryId'");
             while(
    $rowDetailofBackupCategory=mysql_fetch_assoc($resultOfBackupData))
             {

             
    //$rowDetailofBackupCategory=mysql_fetch_assoc(mysql_query("SELECT * FROM category_backup WHERE category_id='$categoryId'"));
             
    $categoryName=$rowDetailofBackupCategory['category_name'];
             
    $categoryDescription=$rowDetailofBackupCategory['category_description'];
             
    $categoryThumbImage=$rowDetailofBackupCategory['category_thumb_image'];
             
    $categoryFullImage=$rowDetailofBackupCategory['category_full_image'];
             
    $mdate=$rowDetailofBackupCategory['mdate'];
             
    $isBrand=$rowDetailofBackupCategory['IsBrand'];
             
    $categoryFromDate=$rowDetailofBackupCategory['category_from_date'];
             
    $categoryUptoDate=$rowDetailofBackupCategory['category_upto_date'];


            


              
    $approvedEditSql="UPDATE category SET
                                        category_name='$categoryName',
                                        category_description='$categoryDescription',
                                        category_thumb_image='$categoryThumbImage',
                                        category_full_image='$categoryFullImage',
                                        mdate='$mdate',
                                        IsBrand='$isBrand',
                                        category_from_date='$categoryFromDate',
                                        category_upto_date='$categoryUptoDate',
                                        category_publish='Y'
                                        WHERE category_id='$categoryId'"
    ;


     

       
         
    mysql_query($approvedEditSql) or die("problem hoche"); 
    Now it is working as expected.

    please give me a reasonable cause why this is happening????????? if u can do it then it would be very nice--
    Last edited by deshi2003; 10-12-2009 at 11:41 AM.

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Posts
    238
    Thanks
    3
    Thanked 37 Times in 37 Posts
    Just an idea: You could try to do it with one query (without selecting to PHP and then updating from there). I did not run it since I do not have your tables but this should give you an idea anyway I think:
    Code:
    UPDATE category AS c, category_backup AS cb
       SET c.category_name=cb.category_name
         , c.category_description=cb.category_description
         , c.category_thumb_image=cb.category_thumb_image
         , c.category_full_image=cb.category_full_image
         , c.mdate=cb.mdate
         , c.IsBrand=cb.IsBrand
         , c.category_from_date=cb.category_from_date
         , c.category_upto_date=cb.category_upto_date
         , c.category_publish='Y'
     WHERE c.category_id=cb.category_id
       AND c.category_id='$categoryId'
    Of course I supposed category_id is the Primary or Unique key both in category and category_backup.

  • Users who have thanked SKDevelopment for this post:

    deshi2003 (10-17-2009)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •