...

View Full Version : How funny it is in PHP. i hate it



deshi2003
10-12-2009, 10:59 AM
Please read this thread carefully. you need a few minutes to read it--

i wrote a script like this ::




$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--





$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--

SKDevelopment
10-12-2009, 11:36 AM
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:


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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum