jakebur01 Posted February 26, 2009 Share Posted February 26, 2009 I have two problems. The first is that if there is not a " WHERE $part LIKE '{$itemNum}% " then I need to add one to the table. The second problem I am having is I need a better way to clean up my rows than to use array('', '$-', '0', '0.0', '0.00', '$ 0', '$ -', '$0.0', '$0.00', '-', ' ', '$', '$- ', '$- '). I would like it if I could delete the rows where it does not have a numeric value above .01 . while ($row = mysql_fetch_assoc($result)) { $itemNum = substr($row[$part], 0, -2); $update = "UPDATE {$tablename} SET $list = '{$row[$list]}', $dealer = '{$row[$dealer]}', $distributor = '{$row[$distributor]}', $sort = '{$row[$sort]}', $stdpack = '{$row[$stdpack]}' WHERE $part LIKE '{$itemNum}%'"; mysql_query($update) or die(mysql_error()); } $inArray = array('', '$-', '0', '0.0', '0.00', '$ 0', '$ -', '$0.0', '$0.00', '-', ' ', '$', '$- ', '$- '); $checkData = implode("', '", $inArray); mysql_query("DELETE FROM {$tablename} WHERE $dealer IN({$checkData}) OR $distributor IN({$checkData}) OR $list IN({$checkData})"); Quote Link to comment https://forums.phpfreaks.com/topic/147081-solved-having-trouble/ Share on other sites More sharing options...
Mark Baker Posted February 26, 2009 Share Posted February 26, 2009 $checkData = "'".implode("', '", $inArray)."'"; Quote Link to comment https://forums.phpfreaks.com/topic/147081-solved-having-trouble/#findComment-772142 Share on other sites More sharing options...
jakebur01 Posted February 26, 2009 Author Share Posted February 26, 2009 What about this? while ($row = mysql_fetch_assoc($result)) { $itemNum = substr($row[$part], 0, -2); $update = "UPDATE {$tablename} SET $list = '{$row[$list]}', $dealer = '{$row[$dealer]}', $distributor = '{$row[$distributor]}', $sort = '{$row[$sort]}', $stdpack = '{$row[$stdpack]}' WHERE $part LIKE '{$itemNum}%'"; mysql_query($update) or die(mysql_error()); } Is there a way I can add the item to the database if it doesn't find it doing an update. Also, I am unsure of how many columns are in the table. It is different every time. But, the only columns I need are the ones specified in the query above. Quote Link to comment https://forums.phpfreaks.com/topic/147081-solved-having-trouble/#findComment-772150 Share on other sites More sharing options...
jakebur01 Posted February 27, 2009 Author Share Posted February 27, 2009 My first problem is fixed but not my second. Quote Link to comment https://forums.phpfreaks.com/topic/147081-solved-having-trouble/#findComment-772241 Share on other sites More sharing options...
jakebur01 Posted February 27, 2009 Author Share Posted February 27, 2009 I know the else is incorrect. How can I do it correctly and insert values into the columns specified and NULL or 0 into the remaining columns? <?php $sql = "SELECT * FROM {$tablename} WHERE ($part LIKE '%-1' OR $part LIKE '%-2' OR $part LIKE '%-3' OR $part LIKE '%-0')"; $result = mysql_query($sql) OR DIE(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $itemNum = substr($row[$part], 0, -2); $sql2 = "SELECT * FROM {$tablename} WHERE $part = $itemNum"; $result2 = mysql_query($sql2) OR DIE(mysql_error()); $num_rows = mysql_num_rows($result2); if($num_rows>0) { $update = "UPDATE {$tablename} SET $list = '{$row[$list]}', $dealer = '{$row[$dealer]}', $distributor = '{$row[$distributor]}', $sort = '{$row[$sort]}', $stdpack = '{$row[$stdpack]}' WHERE $part LIKE '{$itemNum}%'"; mysql_query($update) or die(mysql_error()); } else { $insert = "INSERT INTO {$tablename} VALUES $part = $itemnum, $list = '{$row[$list]}', $dealer = '{$row[$dealer]}', $distributor = '{$row[$distributor]}', $sort = '{$row[$sort]}', $stdpack = '{$row[$stdpack]}'"; mysql_query($update) or die(mysql_error()); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/147081-solved-having-trouble/#findComment-772274 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.