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\">
> <tr><td align=\"center\" colspan=\"3\"><font size=\"4\"><B>Current
> Inventory</B></font><hr color=\"333333\"></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 "<tr><td width=\"30%\"><B>Type Of Car: </B></td><td>";
> 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 "</td><td><input 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 "<tr><td width=\"30%\"><B>Model Of Car: </B></td><td>";
> printf(mysql_result($result,$count,"car_model"));

same as above, replace mysql_result($result,$count,"car_model") with 

> echo "</td></tr>\n";
> echo "<tr><td width=\"30%\"><B>Year Of Car: </B></td><td>";
> printf(mysql_result($result,$count,"car_year"));

same as above replace with $car_year

> echo "</td></tr>\n";
> echo "<tr><td width=\"30%\"><B>Price Of Car: </B></td><td>$";
> printf(mysql_result($result,$count,"car_price"));

same as above replace with $care_price

> echo "</td></tr>\n";
> echo "<tr><td width=\"30%\"><B>VIN Of Car: </B></td><td>";
> printf(mysql_result($result,$count,"car_vin"));

same as above replace with $car_vin

> echo "</td></tr><tr><td colspan=\"3\"><hr color=\"333333\"></td></tr>\n";

$count ++; should go here

> }
> echo "<tr><td><input 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:

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");

> <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\"><B>Confirm Record
> Deletion</B></font><hr color=\"333333\"></td>
>   </tr>
>   <tr>
>     <td width=\"30%\"><B>Type Of Car: </B></td>
>  <td>$car_type</td>
>   </tr>
>   <tr>
>     <td width=\"30%\"><B>Model Of Car: </B></td>
>  <td>$car_model</td>
>   </tr>
>   <tr>
>     <td width=\"30%\"><B>Year Of Car: </B></td>
>  <td>$car_year</td>
>   </tr>
>   <tr>
>     <td width=\"30%\"><B>Price Of Car: </B></td>
>  <td>$car_price</td>
>   </tr>
>   <tr>
>     <td width=\"30%\"><B>VIN Of Car: </B></td>
>  <td>$car_vin</td>
>   </tr>


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=\"333333\"></td>
>   </tr>
>   <tr>
>     <td><input 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";

need another loop here to go through id's passed through array

while ($id[$i]) {

> $sql = "DELETE FROM $table_name WHERE id = '$id'";

this should be 
$sql="DELETE FROM $table_name WHERE id = $id[$i]";

Remove '' around $id and add [], it is an integer, so it does not want quotes 
around it
only quote string datatypes

> echo($sql);
> $result = mysql_query($sql,$dbh) or die(mysql_error());

increment array and then close loop


> 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

This probably has some holes in it and I am sure someone will not hesitate to 
point them out, in fact, please do, feel free.  But that should get you most 
of the way 
to what I believe you are looking for.




PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to