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

Recommended Answers

All 3 Replies

Member Avatar for diafol

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.

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());
}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.