0
For loop error problem
Method:
for($i =0;$i<count('$std_id);$i++)
{
for($j=0;$jcount('$sub_id;$j++)
{
mysql_query("INSERT INTO mmst_tbl(std_id,sub_id,mark)VALUES('$std_id[$i]','$sub_id[$j]','$mark[$j]')");
}
}

How to solve this? instead of 138 rows it goes 2000+ lines

2
Contributors
3
Replies
20
Views
2 Years
Discussion Span
Last Post by diafol
1

This code is seriously messed up.

for($i =0;$i<count('$std_id);$i++)

WHy the single quote?

for($j=0;$jcount('$sub_id;$j++)

Why the single quote? Why no = after the second $j? Why no close bracket after the $sub_id?

mysql_query("INSERT INTO mmst_tbl(std_id,sub_id,mark)VALUES('$std_id[$i]','$sub_id[$j]','$mark[$j]')");

Still using deprecated code (mysql_*)? You are seriously planning to run 138 separate INSERT queries? Why not just build up the VALUES clause as a string then attach it to the main query string and run it ONCE?

PLEASE - get a suitable editor/IDE so that these typos and syntax errors are flagged up, else you run the risk of looking a bit silly.

Edited by diafol

0
for($i =0;$i<count($std_id);$i++)
{
for($j=0;$j<count($sub_id);$j++)
{
mysql_query("INSERT INTO mst_tbl(std_id,sub_id,mark)VALUES('$std_id[$i]','$sub_id[$j]','$mark[$j]')")or die(mysql_error());
}
}

Edited by AntonyRayan

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.