[PHP-DB] Re: Associating table id...
I sincerely wish someone could give me some insight as to what I am doing wrong here. I have been scouring php.net for any website that has a good tutorial or article on how to pass the variables from page to page while assigning a variable a whole record set from a database. If anyone has run into the same problem that I am having please give me a shove in the right direction. Thanks in advance, Jas Jas [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Ok I have been working on this function to delete an item from a mysql database and so far I have not had any success. Here is the problem I am having (after alot of headaches), I need to be able to associate a checkbox to a record or a set of records... For example, page 1 queries a database and pulls the results into a table and in that table is a form with a checkbox for each record pulled from said database... code is here... ?php require '../path/to/db.php'; //connection script $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=\done2.php3\ trtd align=\center\ colspan=\3\font size=\4\BCurrent Inventory/B/fonthr color=\33\/td/tr; $count = -1; while ($myrow = mysql_fetch_row($result)) { $count ++; echo trtd width=\30%\BType Of Car: /B/tdtd; printf(mysql_result($result,$count,car_type)); echo /tdtdinput type=\checkbox\ name=\id\ value=\id\remove/td/tr\n; echo rest of fields in database; } echo trtdinput type=\submit\ name=\delete\ value=\delete\/td/tr/form/table; ? Now what I need to do is to have the checkbox item be associated with all one record set. Table structure is here - | id | car_model | car_type | car_year | car_price | car_vin | dlr_num | - | 0 | ford | bronco| 1997 | 6700 | vin# | dlr # | - etc. etc. From the first page it links to page which queries the db and deletes the selected records... however, I am not able to get the id to be associated with the records in the table... the deletion script is as follows ?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(record deleted); ? If anyone has ever run into this please help... I am still fairly new to php and mysql and there is definately something I am missing here and I think its because I need to associate the checkbox with the id and the id field from the database does not seem to be linked to the rest of the record in said fields... Thanks in advance, Jas And yes I do know I posted the same question yesterday... I still cannot figure this one out. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Associating table id...
All you need to do is assign the variable (let's call it $id) the id for that record set from the database. Then pass this variable to the next page for the delete. You may want to search for the mysql_fetch_array function on php.net. This would be used to grab the record set from the database to display it on the first page and then pass the id part of the array to the second page as $id. There are some good examples on the page that comes up when you enter mysql_fetch_array into the 'function list' search on php.net. HTH MB jas [EMAIL PROTECTED] said: I sincerely wish someone could give me some insight as to what I am doing wrong here. I have been scouring php.net for any website that has a good tutorial or article on how to pass the variables from page to page while assigning a variable a whole record set from a database. If anyone has run into the same problem that I am having please give me a shove in the right direction. Thanks in advance, Jas Jas [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Ok I have been working on this function to delete an item from a mysql database and so far I have not had any success. Here is the problem I am having (after alot of headaches), I need to be able to associate a checkbox to a record or a set of records... For example, page 1 queries a database and pulls the results into a table and in that table is a form with a checkbox for each record pulled from said database... code is here... ?php require '../path/to/db.php'; //connection script $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=\done2.php3\ trtd align=\center\ colspan=\3\font size=\4\BCurrent Inventory/B/fonthr color=\33\/td/tr; $count = -1; while ($myrow = mysql_fetch_row($result)) { $count ++; echo trtd width=\30%\BType Of Car: /B/tdtd; printf(mysql_result($result,$count,car_type)); echo /tdtdinput type=\checkbox\ name=\id\ value=\id\remove/td/tr\n; echo rest of fields in database; } echo trtdinput type=\submit\ name=\delete\ value=\delete\/td/tr/form/table; ? Now what I need to do is to have the checkbox item be associated with all one record set. Table structure is here - | id | car_model | car_type | car_year | car_price | car_vin | dlr_num | - | 0 | ford | bronco| 1997 | 6700 | vin# | dlr # | - etc. etc. From the first page it links to page which queries the db and deletes the selected records... however, I am not able to get the id to be associated with the records in the table... the deletion script is as follows ?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(record deleted); ? If anyone has ever run into this please help... I am still fairly new to php and mysql and there is definately something I am missing here and I think its because I need to associate the checkbox with the id and the id field from the database does not seem to be linked to the rest of the record in said fields... Thanks in advance, Jas And yes I do know I posted the same question yesterday... I still cannot figure this one out. -- 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
[PHP-DB] Re: Associating table id...
You have set the value of the id input element to the literal string 'id'. What you really want to do is set the id element to the primary key of the row in question. To use your coding style: ... $id = sprintf(mysql_result($result,$count,pk_field)); echo /tdtdinput type=\checkbox\ name=\id\ value=\$id\remove/td/tr\n; ... Pete Jas wrote: I sincerely wish someone could give me some insight as to what I am doing wrong here. I have been scouring php.net for any website that has a good tutorial or article on how to pass the variables from page to page while assigning a variable a whole record set from a database. If anyone has run into the same problem that I am having please give me a shove in the right direction. Thanks in advance, Jas Jas [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Ok I have been working on this function to delete an item from a mysql database and so far I have not had any success. Here is the problem I am having (after alot of headaches), I need to be able to associate a checkbox to a record or a set of records... For example, page 1 queries a database and pulls the results into a table and in that table is a form with a checkbox for each record pulled from said database... code is here... ?php require '../path/to/db.php'; //connection script $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=\done2.php3\ trtd align=\center\ colspan=\3\font size=\4\BCurrent Inventory/B/fonthr color=\33\/td/tr; $count = -1; while ($myrow = mysql_fetch_row($result)) { $count ++; echo trtd width=\30%\BType Of Car: /B/tdtd; printf(mysql_result($result,$count,car_type)); echo /tdtdinput type=\checkbox\ name=\id\ value=\id\remove/td/tr\n; echo rest of fields in database; } echo trtdinput type=\submit\ name=\delete\ value=\delete\/td/tr/form/table; ? Now what I need to do is to have the checkbox item be associated with all one record set. Table structure is here - | id | car_model | car_type | car_year | car_price | car_vin | dlr_num | - | 0 | ford | bronco| 1997 | 6700 | vin# | dlr # | - etc. etc. From the first page it links to page which queries the db and deletes the selected records... however, I am not able to get the id to be associated with the records in the table... the deletion script is as follows ?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(record deleted); ? If anyone has ever run into this please help... I am still fairly new to php and mysql and there is definately something I am missing here and I think its because I need to associate the checkbox with the id and the id field from the database does not seem to be linked to the rest of the record in said fields... Thanks in advance, Jas And yes I do know I posted the same question yesterday... I still cannot figure this one out. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php