Email address obfuscation in effect -- please
click here to turn it off.
[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
mehmood hasan wrote:
>
> hi
>
> according to ur opinion i made the select and insert process saperate
> like that
> $ins = "select * from markstable where subjects = 'CHM' and province =
> 'P' order by m_marks desc limit 10";
> $insert = mysql_query($ins);
>
If the "limit 10" expression works in your database, you shouldn't have to do
any of the below programming - you'll already be selecting only 10 records. Go
back to your original SQL query and add "limit 10" to it, and that should be all.
>
>
> it works well
> but in next step i want to insert that selected values from array to
> table "chemistry" like that
> while ($row=mysql_fetch_array($insert))
> {
> for($i=1; $i<=10; $i++)
> {
> mysql_query ("INSERT INTO chemistry
> (f_name,l_name,id,m_marks,province,subjects) values
> ($row[f_name],$row[l_name],$row[id],$row[m_marks],$row[province],$row[subjects])");
>
> }
> }
>
> but this step does not work and failed to insert values in table
> "chemistry".... can I insert values from array to table
> please tell me how
> thanx
> mehmood
>
Besides the problem with quotes, the above code inserts the same row 10 times,
and you still insert all the rows returned by the database. What you should do
is something like:
for($i=1; $i<=10; $i++)
{
$row=mysql_fetch_array($insert);
if (!$row) break;
mysql_query ("INSERT INTO chemistry
(f_name,l_name,id,m_marks,province,subjects) values (" . $row["f_name"] . ","
. $row["l_name"] . "," . $row["id"] . "," . $row["m_marks"] . "," .
$row["province"] . "," . $row["subjects] . ")");
}
--
MK
_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members