If this is all you’re echoing from your PHP isn’t “12345” what the output would be if it echoes the results, one after the other? So wouldn’t the following instead do the job (unless I have misunderstood):
Actually I ran the second enquiry inside the loop because I want to choose which student id from student_lists table who has mark=1 then I select student_datail from another table. so Student_details is depend on student_lists.
You still haven’t told us how you know which one you want to print.
You have been stating what you are trying to make work. However, this doesn’t tell us what the overall goal is, in a programming/web page context. I suspect the answer will be that you want to produce links, with each id in them, that you can then click to get more information?
Actually I want to store every value in the fetch array in separate variable for example the output “12345” need to take “1” and store it in variable $x1, “2” in variable$x2, “3” in variable$x3 and so on…
So have I understood the aim correctly? (I think you have got the above bit wrong - you are comparing the id with a score?):
You want to echo out each student’s name and then either the word “pass” or the word “fail” depending on their mark?
If so, then it can certainly be done without having a query in a loop. You run a query with a JOIN and then loop through the result to create the output, outputting “pass” or “fail” depending on the mark.
I have a couple of observations/questions, looking at your database tables. I think the “id” in the “student_lists” (primary key) corresponds with the “Class_id” in the “student_detail” table, where it is a foreign key? And the “id” in the “Class_id” table is the primary key for that table? If that id correct I would rename with column titles, to, for example, the following: student_lists
student_id
studentName
Mark
student_detail (Which I might retitle exam_results)
result_id
student_id
result
I may have misunderstood things here though.
I’m not sure what the column “Mark” is in the “student_lists” column?
I hope I am not patronising you here - if I am I apologise.
If you don’t know the meaning of “primary key” and “foreign key” then I would Google them and SQL JOINS - it will make things much clearer. I suspect things may suddenly click in your mind and you will have then have a clearer view of how to proceed.