PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
vincenzobar
Forum Commoner
Posts: 95 Joined: Wed Nov 02, 2005 9:57 am
Post
by vincenzobar » Wed Nov 09, 2005 5:03 pm
once again ...
Code: Select all
$move = array();
$f_move = array();
if(in_array($p_id, $DB_IDList)) {
$db_row = mysql_fetch_row($all_rows);
array_map('mysql_real_escape_string', $db_row);
$move[] = "'', "."'".implode("', '", $db_row)."'";
$f_move[] = "(".implode(', ', $move). ")";
$moved = implode(", ", $f_move);
print $moved;
$archive = 'INSERT INTO archive_rateplan VALUES '.$moved.'';
mysql_query($archive) or die(mysql_error());
$delete = 'DELETE FROM CB_rateplan WHERE productid = '.$p_id.';';// delete
mysql_query($delete) or die(mysql_error());
}
it leaves 87 records only moves 120 to archive and dies. if i comment it out it moves and re-updates CB_rateplan with XML Parse.
Why is it Dying??? This is driving me nutz!
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Wed Nov 09, 2005 5:15 pm
what i have always seen as in a INSERT query you need the row names before the value but i could be wrong that this is needed. otherwise please make whats happening a little bit clearer because i could not quite understand. does it die with a error? if so what is that error?
Charles256
DevNet Resident
Posts: 1375 Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 » Wed Nov 09, 2005 5:18 pm
you don't specify what you want to delete frmo that row, if you want to delete the entire row then do DELETE * (rest of statement)
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Wed Nov 09, 2005 5:20 pm
Charles256 wrote: you don't specify what you want to delete frmo that row, if you want to delete the entire row then do DELETE * (rest of statement)
if he just wants to delete the entire row then what he has is perfectly jegit, i use that all the time
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Wed Nov 09, 2005 5:21 pm
shiznatix wrote: what i have always seen as in a INSERT query you need the row names before the value but i could be wrong that this is needed. otherwise please make whats happening a little bit clearer because i could not quite understand. does it die with a error? if so what is that error?
it isn't necessary as long as the number of values match up with the number of columns on the table and the datatypes jive.
what are you trying to do with array_map() there? What error messages are you getting?
edit: ok, I see what you're doing with array_map(), never used it like that...
Last edited by
Burrito on Wed Nov 09, 2005 5:25 pm, edited 1 time in total.
Charles256
DevNet Resident
Posts: 1375 Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 » Wed Nov 09, 2005 5:21 pm
ah. I always throw in a star... : shrugs :
edit:
I think I'm being retarded. Just ignore me.
vincenzobar
Forum Commoner
Posts: 95 Joined: Wed Nov 02, 2005 9:57 am
Post
by vincenzobar » Wed Nov 09, 2005 5:29 pm
I will try a star * but i want the whole row gone!
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Wed Nov 09, 2005 5:35 pm
don't use a *. i have never seen it used in a delete query before. but what exactally are you trying to do and what exactally is the error when it dies? these are important things
Charles256
DevNet Resident
Posts: 1375 Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 » Wed Nov 09, 2005 5:36 pm
yeah,don't use a *, which is why I said I was being retarded:-D
vincenzobar
Forum Commoner
Posts: 95 Joined: Wed Nov 02, 2005 9:57 am
Post
by vincenzobar » Wed Nov 09, 2005 5:38 pm
lol, no kidding!!!
i am Looping through a XML page and grabbing data then i use the data in the XML array to check against the database. If the XML Product id matches the database product id then..
move data from BC database to archive then delete it then insert new records from XML sheet. that simple
but NOT!!!
vincenzobar
Forum Commoner
Posts: 95 Joined: Wed Nov 02, 2005 9:57 am
Post
by vincenzobar » Wed Nov 09, 2005 5:40 pm
here is all the code on the page.
Code: Select all
include_once ( 'xmlparser.php' );
include_once ( 'mysql_func.inc.php' );
$data = file_get_contents ( 'rpdf.xml' );
$data = process_xml ( $data );
$hold = array ();
$x = 0;
foreach ( $data['ROOT'] AS $rn => $rv )
{
if ( is_array ( $rv ) )
{
foreach ( $rv AS $pn => $pv )
{
if ( is_array ( $pv ) )
{
foreach ( $pv AS $cn => $cv )
{
if ( is_array ( $cv ) )
{
foreach ( $cv AS $an => $av )
{
if ( is_array ( $av ) )
{
$temp = array ();
$column = array();
foreach ( $av AS $dn => $dv )
{
$hold1[] = strtolower($dn);
$temp[] = addslashes ( trim ( ( ! empty ( $temp ) ? strtolower ( $dv ) : $dv ) ) );
}
$column = array_unique($hold1);
$rows = "(".implode(", ", $column). ")";
$hold[$x] = "( '" . implode ( "', '", $temp ) . "' )";
$values = implode ( ', ', $hold );
//store XML IDs in an array...
$XML_IDList[] = $temp[21];
$x++;
}
}
}
}
}
}
}
}
//We are going gangsta today
//insert SQL Statement
//Queries
$query_rp = "SELECT productid FROM CB_rateplan;";
$results_rp = mysql_query($query_rp);
$num_rows_rp = mysql_num_rows($results_rp);
//$sql = "INSERT INTO CB_rateplan $rows VALUES " . implode ( ', ', $hold ).";";
$add_rp = "INSERT INTO CB_rateplan $rows VALUES $values;";
// insert data from XML file
if(!empty($num_rows_rp)){
//fetch all the DB IDs in an array to reduce tons of DB query...
$idrs = mysql_query("SELECT productid FROM CB_rateplan;") or die(mysql_error());
$add_rp = "INSERT INTO CB_rateplan $rows VALUES $values;";
while($row = mysql_fetch_row($idrs)){
$DB_IDList[] = $row[0];
$Update_Query = "UPDATE CB_rateplan SET <1> WHERE productid=<2>";
}
//match and update/add as needed... trifle now
foreach($XML_IDList as $p_id) {
//print "p_id; ".$p_id. "<BR>";
$all_rows = mysql_query('SELECT * FROM CB_rateplan WHERE productid = '.$p_id.';');// get rows from production table
//insert matching rows into archive table
$move = array();
$f_move = array();
if(in_array($p_id, $DB_IDList)) {
$db_row = mysql_fetch_row($all_rows);
$dbf_row = array_map('mysql_real_escape_string', $db_row);
$move[] = "'', "."'".implode("', '", $dbf_row)."'";
$f_move[] = "(".implode(', ', $move). ")";
$moved = implode(", ", $f_move);
print $moved;
$archive = 'INSERT INTO archive_rateplan VALUES '.$moved.'';
mysql_query($archive) or die(mysql_error());
$delete = 'DELETE FROM CB_rateplan WHERE productid = '.$p_id.';';//Delete all matching products after they have been archived
mysql_query($delete) or die(mysql_error());
}
}
mysql_query($add_rp) or die(mysql_error());
}else { //if 2
mysql_query($add_rp);
echo $add_rp;
}//FIRST IF*/
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Wed Nov 09, 2005 5:40 pm
so where are you getting the error?
vincenzobar
Forum Commoner
Posts: 95 Joined: Wed Nov 02, 2005 9:57 am
Post
by vincenzobar » Wed Nov 09, 2005 5:42 pm
no error just stops short but page parses through everything runs but all records don't move and the re-insert never goes through which makes me think it just stops
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Wed Nov 09, 2005 5:44 pm
do you have error reporting on?