Forum Moderators: coopster

Message Too Old, No Replies

Acquiring user selected records from a DB

         

Esqulax

3:38 pm on Feb 25, 2008 (gmt 0)

10+ Year Member



I have a post above asking about the update query.. all good..
I'd like to do this on multiple records at a time, but am having trouble getting them to display.
My model is a car database.


<?php

echo('<form method="post" action="'.$self.'">');
$delid = $_POST['carid'];
$how_many=count($delid);

if ($how_many>0)
{

$sql1= "SELECT * FROM cars WHERE car_id = $delid";
$rs=mysql_query($sql1,$conn);

while($row = mysql_fetch_array($rs))
{
echo ("EDITING records:<br>");

for ($i=0; $i<$how_many; $i++)
{
echo (($i+1) . " - " . $delid[$i] . "<br>");
echo ('Reg No:<input type="text" name="reg" size="8" value="'.$row["reg_no"].'">');
}
echo('</form>');
}
}
?>

carid is the array in which the options from the HTML checkbox form are stored. the INT value of these are correspondent to the values of the primary key in the table.

Im getting : Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in editcar.php on line 55

(i intend to put the update code underneath it all, so it updates when the second new button is pressed, hence the $self in the second form)

[edited by: Esqulax at 3:42 pm (utc) on Feb. 25, 2008]

Esqulax

3:57 pm on Feb 25, 2008 (gmt 0)

10+ Year Member



Could it be that i cant access the same table twice without closing it first? (i had to open it to select the data before this code)

Esqulax

4:17 pm on Feb 25, 2008 (gmt 0)

10+ Year Member



Sorted it...
for those keeping track...


echo('<form method="post" action="'.$self.'">');
$delid = $_POST['carid'];
$how_many=count($delid);

if($how_many>0){

foreach ($_POST['carid'] as $val)
{

$sql = "SELECT * FROM cars WHERE car_id = '$val'";
$rs1=(mysql_query($sql));

while($row = mysql_fetch_array($rs1))
{
echo ('Reg No:<input type="text" name="reg" size="8" value="'.$row["reg_no"].'"><br>');
echo('</form>');

}
}

}

methinks i got a bit confused with the $_POST being an array