Re: [PHP-DB] Array HELL!!!!
Try putting the hidden element statement down inside the while loop in he second page, but change it to INPUT TYPE=\hidden\ NAME=\id[]\ VALUE=\$id\ and add $id=$row['id']; before it. I will show below where it should go. HTH MB jas [EMAIL PROTECTED] said: I have made the changes you suggested which if you ask me have been the most informative answers I have recieved thus far. I did run into a slight snag on line 21 which is this on my confirmation page INPUT TYPE=\hidden\ NAME=\id[]\ VALUE=\$id[]\ and the parse error is as follows... Parse error: parse error, expecting `STRING' or `NUM_STRING' or `'$'' in /php/rem_conf_t.php3 on line 21 Wouldn't I need to adjust the value=\$id[]\ to something like value=\.$id[].\ because we passed an array not a string? Not sure. Thanks again. You are sincerely helping me understand this whole php bit. =) Jas [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Ok, you have almost got it. I have made little remarks further down in your code which should just about do it for you. jas [EMAIL PROTECTED] said: I don't know what it is but I am having a hell of a time trying to get some results of a query setup into an array or variable (too much of a newbie to know which) that can be passed to a confirmation page before deleting the record from a table. I have given up working on this but for those of you that want to finish it here is the code and the table structure... [Table Structure] id int(30) DEFAULT '0' NOT NULL auto_increment, car_type varchar(30), car_model varchar(30), car_year varchar(15), car_price varchar(15), car_vin varchar(25), dlr_num varchar(25), PRIMARY KEY (id) [Page 1 - Queries DB table for records] ?php require '../path/to/db.php'; $result = @mysql_query(SELECT * FROM cur_inv,$dbh) or die(Could not execute query, please try again later); echo table border=\0\ class=\table-body\ width=\100%\form name=\rem_inv\ method=\post\ action=\rem_conf.php3\ trtd align=\center\ colspan=\3\font size=\4\BCurrent Inventory/B/fonthr color=\33\/td/tr; $count = -1; $count should start at 0 and then increment at the bottom of the while loop while ($myrow = mysql_fetch_array($result)) { $id = $row[id]; $row should be $myrow since that is what it is called above (or change $myrow above to $row) $car_type = $row[car_type]; $car_model = $row[car_model]; $car_year = $row[car_year]; $car_price = $row[car_price]; $car_vin = $row[car_vin]; $count ++; $count ++; should be moved to the bottom of the loop just before it is closed echo trtd width=\30%\BType Of Car: /B/tdtd; printf(mysql_result($result,$count,car_type)); mysql_result is not needed here, you have defined the variable $car_type to be this here as well as the rows below, so replace mysql_result($result, $count, car_type) with just $car_type echo /tdtdinput type=\checkbox\ name=\id[]\ value=\.$myrow[id].\remove/td/tr\n; replace $myrow[id] with $id since it is already defined above when id[] is passed to page 2, it will contain an array of the id numbers that got checked echo trtd width=\30%\BModel Of Car: /B/tdtd; printf(mysql_result($result,$count,car_model)); same as above, replace mysql_result($result,$count,car_model) with $car_model echo /td/tr\n; echo trtd width=\30%\BYear Of Car: /B/tdtd; printf(mysql_result($result,$count,car_year)); same as above replace with $car_year echo /td/tr\n; echo trtd width=\30%\BPrice Of Car: /B/tdtd$; printf(mysql_result($result,$count,car_price)); same as above replace with $care_price echo /td/tr\n; echo trtd width=\30%\BVIN Of Car: /B/tdtd; printf(mysql_result($result,$count,car_vin)); same as above replace with $car_vin echo /td/trtrtd colspan=\3\hr color=\33\/td/tr\n; $count ++; should go here } echo trtdinput type=\submit\ name=\delete\ value=\delete\/td/tr/form/table; ? [Page 2 - Takes records and confirms which ones to be deleted] ?php print( table border=\0\ class=\table-body\ width=\100%\ form name=\rem_inv\ method=\post\ action=\done2.php3\ send id[] array passed from previous page to the next page: INPUT TYPE=\hidden\ NAME=\id[]\ VALUE=\$id[]\ If you are planning on deleting multiple items at a time, you won't need the following hidden elements at all, just make a database call at this point using the id[] array passed to this page from the first page. The only value it needs for the 3rd page is the id value since that is what it uses to determine what to delete. Here is an example of the database call to make: $i=0; while ($id[$i]) { $result = @mysql_query(SELECT * FROM cur_inv where id=$id[$i],$dbh) or die (Could not execute query, please try again later);
[PHP-DB] Array HELL!!!!
I don't know what it is but I am having a hell of a time trying to get some results of a query setup into an array or variable (too much of a newbie to know which) that can be passed to a confirmation page before deleting the record from a table. I have given up working on this but for those of you that want to finish it here is the code and the table structure... [Table Structure] id int(30) DEFAULT '0' NOT NULL auto_increment, car_type varchar(30), car_model varchar(30), car_year varchar(15), car_price varchar(15), car_vin varchar(25), dlr_num varchar(25), PRIMARY KEY (id) [Page 1 - Queries DB table for records] ?php require '../path/to/db.php'; $result = @mysql_query(SELECT * FROM cur_inv,$dbh) or die(Could not execute query, please try again later); echo table border=\0\ class=\table-body\ width=\100%\form name=\rem_inv\ method=\post\ action=\rem_conf.php3\ trtd align=\center\ colspan=\3\font size=\4\BCurrent Inventory/B/fonthr color=\33\/td/tr; $count = -1; while ($myrow = mysql_fetch_array($result)) { $id = $row[id]; $car_type = $row[car_type]; $car_model = $row[car_model]; $car_year = $row[car_year]; $car_price = $row[car_price]; $car_vin = $row[car_vin]; $count ++; echo trtd width=\30%\BType Of Car: /B/tdtd; printf(mysql_result($result,$count,car_type)); echo /tdtdinput type=\checkbox\ name=\id[]\ value=\.$myrow[id].\remove/td/tr\n; echo trtd width=\30%\BModel Of Car: /B/tdtd; printf(mysql_result($result,$count,car_model)); echo /td/tr\n; echo trtd width=\30%\BYear Of Car: /B/tdtd; printf(mysql_result($result,$count,car_year)); echo /td/tr\n; echo trtd width=\30%\BPrice Of Car: /B/tdtd$; printf(mysql_result($result,$count,car_price)); echo /td/tr\n; echo trtd width=\30%\BVIN Of Car: /B/tdtd; printf(mysql_result($result,$count,car_vin)); echo /td/trtrtd colspan=\3\hr color=\33\/td/tr\n; } echo trtdinput type=\submit\ name=\delete\ value=\delete\/td/tr/form/table; ? [Page 2 - Takes records and confirms which ones to be deleted] ?php print( table border=\0\ class=\table-body\ width=\100%\ form name=\rem_inv\ method=\post\ action=\done2.php3\ INPUT TYPE=\hidden\ NAME=\id\ VALUE=\$id\ INPUT TYPE=\hidden\ NAME=\car_type\ VALUE=\$car_type\ INPUT TYPE=\hidden\ NAME=\car_model\ VALUE=\$car_model\ INPUT TYPE=\hidden\ NAME=\car_year\ VALUE=\$car_year\ INPUT TYPE=\hidden\ NAME=\car_price\ VALUE=\$car_price\ INPUT TYPE=\hidden\ NAME=\car_vin\ VALUE=\$car_vin\ tr td align=\center\ colspan=\3\font size=\4\BConfirm Record Deletion/B/fonthr color=\33\/td /tr tr td width=\30%\BType Of Car: /B/td td$car_type/td /tr tr td width=\30%\BModel Of Car: /B/td td$car_model/td /tr tr td width=\30%\BYear Of Car: /B/td td$car_year/td /tr tr td width=\30%\BPrice Of Car: /B/td td$car_price/td /tr tr td width=\30%\BVIN Of Car: /B/td td$car_vin/td /tr tr td colspan=\3\hr color=\33\/td /tr tr tdinput type=\submit\ name=\delete\ value=\delete\/td /tr /form /table); ? [Page 3 - Connects to DB and deletes selected records] ?php require '../path/to/db.php'; $table_name = cur_inv; $sql = DELETE FROM $table_name WHERE id = '$id'; echo($sql); $result = mysql_query($sql,$dbh) or die(mysql_error()); print(body bgcolor=\ff9900\p class=\done\You have successfully removed your items from the database.); ? If anyone has the time to finish it or give me some pointers on what the hell I am doing wrong please let me know, I would be very glad to hear your opinion and the correct way to accomplish this. (And, yes I went through just about every tutorial I could find on how to delete records, which by the way did nothing for putting the results of a select statement into an array or variable for futher processing.) Have a good weekend everyone!!! Pissed and frustrated... Jas -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Array HELL!!!!
That's not Array Hell, this is Array Hell: $Hell = array(satan,fire,brimstone); -Mike -Original Message- From: jas [mailto:[EMAIL PROTECTED]] Sent: Friday, February 22, 2002 4:37 AM To: [EMAIL PROTECTED] Subject: [PHP-DB] Array HELL I don't know what it is but I am having a hell of a time trying to get some results of a query setup into an array or variable (too much of a newbie to know which) that can be passed to a confirmation page before deleting the record from a table. I have given up working on this but for those of you that want to finish it here is the code and the table structure... [Table Structure] id int(30) DEFAULT '0' NOT NULL auto_increment, car_type varchar(30), car_model varchar(30), car_year varchar(15), car_price varchar(15), car_vin varchar(25), dlr_num varchar(25), PRIMARY KEY (id) [Page 1 - Queries DB table for records] ?php require '../path/to/db.php'; $result = @mysql_query(SELECT * FROM cur_inv,$dbh) or die(Could not execute query, please try again later); echo table border=\0\ class=\table-body\ width=\100%\form name=\rem_inv\ method=\post\ action=\rem_conf.php3\ trtd align=\center\ colspan=\3\font size=\4\BCurrent Inventory/B/fonthr color=\33\/td/tr; $count = -1; while ($myrow = mysql_fetch_array($result)) { $id = $row[id]; $car_type = $row[car_type]; $car_model = $row[car_model]; $car_year = $row[car_year]; $car_price = $row[car_price]; $car_vin = $row[car_vin]; $count ++; echo trtd width=\30%\BType Of Car: /B/tdtd; printf(mysql_result($result,$count,car_type)); echo /tdtdinput type=\checkbox\ name=\id[]\ value=\.$myrow[id].\remove/td/tr\n; echo trtd width=\30%\BModel Of Car: /B/tdtd; printf(mysql_result($result,$count,car_model)); echo /td/tr\n; echo trtd width=\30%\BYear Of Car: /B/tdtd; printf(mysql_result($result,$count,car_year)); echo /td/tr\n; echo trtd width=\30%\BPrice Of Car: /B/tdtd$; printf(mysql_result($result,$count,car_price)); echo /td/tr\n; echo trtd width=\30%\BVIN Of Car: /B/tdtd; printf(mysql_result($result,$count,car_vin)); echo /td/trtrtd colspan=\3\hr color=\33\/td/tr\n; } echo trtdinput type=\submit\ name=\delete\ value=\delete\/td/tr/form/table; ? [Page 2 - Takes records and confirms which ones to be deleted] ?php print( table border=\0\ class=\table-body\ width=\100%\ form name=\rem_inv\ method=\post\ action=\done2.php3\ INPUT TYPE=\hidden\ NAME=\id\ VALUE=\$id\ INPUT TYPE=\hidden\ NAME=\car_type\ VALUE=\$car_type\ INPUT TYPE=\hidden\ NAME=\car_model\ VALUE=\$car_model\ INPUT TYPE=\hidden\ NAME=\car_year\ VALUE=\$car_year\ INPUT TYPE=\hidden\ NAME=\car_price\ VALUE=\$car_price\ INPUT TYPE=\hidden\ NAME=\car_vin\ VALUE=\$car_vin\ tr td align=\center\ colspan=\3\font size=\4\BConfirm Record Deletion/B/fonthr color=\33\/td /tr tr td width=\30%\BType Of Car: /B/td td$car_type/td /tr tr td width=\30%\BModel Of Car: /B/td td$car_model/td /tr tr td width=\30%\BYear Of Car: /B/td td$car_year/td /tr tr td width=\30%\BPrice Of Car: /B/td td$car_price/td /tr tr td width=\30%\BVIN Of Car: /B/td td$car_vin/td /tr tr td colspan=\3\hr color=\33\/td /tr tr tdinput type=\submit\ name=\delete\ value=\delete\/td /tr /form /table); ? [Page 3 - Connects to DB and deletes selected records] ?php require '../path/to/db.php'; $table_name = cur_inv; $sql = DELETE FROM $table_name WHERE id = '$id'; echo($sql); $result = mysql_query($sql,$dbh) or die(mysql_error()); print(body bgcolor=\ff9900\p class=\done\You have successfully removed your items from the database.); ? If anyone has the time to finish it or give me some pointers on what the hell I am doing wrong please let me know, I would be very glad to hear your opinion and the correct way to accomplish this. (And, yes I went through just about every tutorial I could find on how to delete records, which by the way did nothing for putting the results of a select statement into an array or variable for futher processing.) Have a good weekend everyone!!! Pissed and frustrated... Jas -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Array HELL!!!!
Well ok now that I know it isn't an array I am having problems with, how exactly am I supposed to create a variable (that can be passed to another page) from a selected set of records? Thanks again for the politeness, Jas Spyproductions Support Team [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... That's not Array Hell, this is Array Hell: $Hell = array(satan,fire,brimstone); -Mike -Original Message- From: jas [mailto:[EMAIL PROTECTED]] Sent: Friday, February 22, 2002 4:37 AM To: [EMAIL PROTECTED] Subject: [PHP-DB] Array HELL I don't know what it is but I am having a hell of a time trying to get some results of a query setup into an array or variable (too much of a newbie to know which) that can be passed to a confirmation page before deleting the record from a table. I have given up working on this but for those of you that want to finish it here is the code and the table structure... [Table Structure] id int(30) DEFAULT '0' NOT NULL auto_increment, car_type varchar(30), car_model varchar(30), car_year varchar(15), car_price varchar(15), car_vin varchar(25), dlr_num varchar(25), PRIMARY KEY (id) [Page 1 - Queries DB table for records] ?php require '../path/to/db.php'; $result = @mysql_query(SELECT * FROM cur_inv,$dbh) or die(Could not execute query, please try again later); echo table border=\0\ class=\table-body\ width=\100%\form name=\rem_inv\ method=\post\ action=\rem_conf.php3\ trtd align=\center\ colspan=\3\font size=\4\BCurrent Inventory/B/fonthr color=\33\/td/tr; $count = -1; while ($myrow = mysql_fetch_array($result)) { $id = $row[id]; $car_type = $row[car_type]; $car_model = $row[car_model]; $car_year = $row[car_year]; $car_price = $row[car_price]; $car_vin = $row[car_vin]; $count ++; echo trtd width=\30%\BType Of Car: /B/tdtd; printf(mysql_result($result,$count,car_type)); echo /tdtdinput type=\checkbox\ name=\id[]\ value=\.$myrow[id].\remove/td/tr\n; echo trtd width=\30%\BModel Of Car: /B/tdtd; printf(mysql_result($result,$count,car_model)); echo /td/tr\n; echo trtd width=\30%\BYear Of Car: /B/tdtd; printf(mysql_result($result,$count,car_year)); echo /td/tr\n; echo trtd width=\30%\BPrice Of Car: /B/tdtd$; printf(mysql_result($result,$count,car_price)); echo /td/tr\n; echo trtd width=\30%\BVIN Of Car: /B/tdtd; printf(mysql_result($result,$count,car_vin)); echo /td/trtrtd colspan=\3\hr color=\33\/td/tr\n; } echo trtdinput type=\submit\ name=\delete\ value=\delete\/td/tr/form/table; ? [Page 2 - Takes records and confirms which ones to be deleted] ?php print( table border=\0\ class=\table-body\ width=\100%\ form name=\rem_inv\ method=\post\ action=\done2.php3\ INPUT TYPE=\hidden\ NAME=\id\ VALUE=\$id\ INPUT TYPE=\hidden\ NAME=\car_type\ VALUE=\$car_type\ INPUT TYPE=\hidden\ NAME=\car_model\ VALUE=\$car_model\ INPUT TYPE=\hidden\ NAME=\car_year\ VALUE=\$car_year\ INPUT TYPE=\hidden\ NAME=\car_price\ VALUE=\$car_price\ INPUT TYPE=\hidden\ NAME=\car_vin\ VALUE=\$car_vin\ tr td align=\center\ colspan=\3\font size=\4\BConfirm Record Deletion/B/fonthr color=\33\/td /tr tr td width=\30%\BType Of Car: /B/td td$car_type/td /tr tr td width=\30%\BModel Of Car: /B/td td$car_model/td /tr tr td width=\30%\BYear Of Car: /B/td td$car_year/td /tr tr td width=\30%\BPrice Of Car: /B/td td$car_price/td /tr tr td width=\30%\BVIN Of Car: /B/td td$car_vin/td /tr tr td colspan=\3\hr color=\33\/td /tr tr tdinput type=\submit\ name=\delete\ value=\delete\/td /tr /form /table); ? [Page 3 - Connects to DB and deletes selected records] ?php require '../path/to/db.php'; $table_name = cur_inv; $sql = DELETE FROM $table_name WHERE id = '$id'; echo($sql); $result = mysql_query($sql,$dbh) or die(mysql_error()); print(body bgcolor=\ff9900\p class=\done\You have successfully removed your items from the database.); ? If anyone has the time to finish it or give me some pointers on what the hell I am doing wrong please let me know, I would be very glad to hear your opinion and the correct way to accomplish this. (And, yes I went through just about every tutorial I could find on how to delete records, which by the way did nothing for putting the results of a select statement into an array or variable for futher processing.) Have a good weekend everyone!!! Pissed and frustrated... Jas -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Array HELL!!!!
Ok, you have almost got it. I have made little remarks further down in your code which should just about do it for you. jas [EMAIL PROTECTED] said: I don't know what it is but I am having a hell of a time trying to get some results of a query setup into an array or variable (too much of a newbie to know which) that can be passed to a confirmation page before deleting the record from a table. I have given up working on this but for those of you that want to finish it here is the code and the table structure... [Table Structure] id int(30) DEFAULT '0' NOT NULL auto_increment, car_type varchar(30), car_model varchar(30), car_year varchar(15), car_price varchar(15), car_vin varchar(25), dlr_num varchar(25), PRIMARY KEY (id) [Page 1 - Queries DB table for records] ?php require '../path/to/db.php'; $result = @mysql_query(SELECT * FROM cur_inv,$dbh) or die(Could not execute query, please try again later); echo table border=\0\ class=\table-body\ width=\100%\form name=\rem_inv\ method=\post\ action=\rem_conf.php3\ trtd align=\center\ colspan=\3\font size=\4\BCurrent Inventory/B/fonthr color=\33\/td/tr; $count = -1; $count should start at 0 and then increment at the bottom of the while loop while ($myrow = mysql_fetch_array($result)) { $id = $row[id]; $row should be $myrow since that is what it is called above (or change $myrow above to $row) $car_type = $row[car_type]; $car_model = $row[car_model]; $car_year = $row[car_year]; $car_price = $row[car_price]; $car_vin = $row[car_vin]; $count ++; $count ++; should be moved to the bottom of the loop just before it is closed echo trtd width=\30%\BType Of Car: /B/tdtd; printf(mysql_result($result,$count,car_type)); mysql_result is not needed here, you have defined the variable $car_type to be this here as well as the rows below, so replace mysql_result($result, $count, car_type) with just $car_type echo /tdtdinput type=\checkbox\ name=\id[]\ value=\.$myrow[id].\remove/td/tr\n; replace $myrow[id] with $id since it is already defined above when id[] is passed to page 2, it will contain an array of the id numbers that got checked echo trtd width=\30%\BModel Of Car: /B/tdtd; printf(mysql_result($result,$count,car_model)); same as above, replace mysql_result($result,$count,car_model) with $car_model echo /td/tr\n; echo trtd width=\30%\BYear Of Car: /B/tdtd; printf(mysql_result($result,$count,car_year)); same as above replace with $car_year echo /td/tr\n; echo trtd width=\30%\BPrice Of Car: /B/tdtd$; printf(mysql_result($result,$count,car_price)); same as above replace with $care_price echo /td/tr\n; echo trtd width=\30%\BVIN Of Car: /B/tdtd; printf(mysql_result($result,$count,car_vin)); same as above replace with $car_vin echo /td/trtrtd colspan=\3\hr color=\33\/td/tr\n; $count ++; should go here } echo trtdinput type=\submit\ name=\delete\ value=\delete\/td/tr/form/table; ? [Page 2 - Takes records and confirms which ones to be deleted] ?php print( table border=\0\ class=\table-body\ width=\100%\ form name=\rem_inv\ method=\post\ action=\done2.php3\ send id[] array passed from previous page to the next page: INPUT TYPE=\hidden\ NAME=\id[]\ VALUE=\$id[]\ If you are planning on deleting multiple items at a time, you won't need the following hidden elements at all, just make a database call at this point using the id[] array passed to this page from the first page. The only value it needs for the 3rd page is the id value since that is what it uses to determine what to delete. Here is an example of the database call to make: $i=0; while ($id[$i]) { $result = @mysql_query(SELECT * FROM cur_inv where id=$id[$i],$dbh) or die (Could not execute query, please try again later); $row=mysql_fetch_array($result); $car_type=$row['car_type']; $car_model=$row['car_model']; $car_year=$row['car_year']; $car_price=$row['car_price']; $car_vin=$row['car_vin']; INPUT TYPE=\hidden\ NAME=\id\ VALUE=\$id\ INPUT TYPE=\hidden\ NAME=\car_type\ VALUE=\$car_type\ INPUT TYPE=\hidden\ NAME=\car_model\ VALUE=\$car_model\ INPUT TYPE=\hidden\ NAME=\car_year\ VALUE=\$car_year\ INPUT TYPE=\hidden\ NAME=\car_price\ VALUE=\$car_price\ INPUT TYPE=\hidden\ NAME=\car_vin\ VALUE=\$car_vin\ tr td align=\center\ colspan=\3\font size=\4\BConfirm Record Deletion/B/fonthr color=\33\/td /tr tr td width=\30%\BType Of Car: /B/td td$car_type/td /tr tr td width=\30%\BModel Of Car: /B/td td$car_model/td /tr tr td width=\30%\BYear Of Car: /B/td td$car_year/td /tr tr td width=\30%\BPrice Of Car: /B/td td$car_price/td /tr tr td width=\30%\BVIN Of Car: /B/td td$car_vin/td /tr $i++; end loop here or after hr (wherever you prefer if you want hr between each item end after hr) ?}? tr td colspan=\3\hr color=\33\/td /tr tr tdinput type=\submit\ name=\delete\ value=\delete\/td