Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,195,756 members, 7,959,350 topics. Date: Thursday, 26 September 2024 at 03:11 PM

How To Get Unknown Data That Has Been Displayed On A Page From Mysql Database - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / How To Get Unknown Data That Has Been Displayed On A Page From Mysql Database (1147 Views)

DHTMLSQL - A Very Advanced Wrapper For Mysql Database! / Most Used Mysql Database Functions / Android Quiz Application With Json Parser, Php And Mysql Database (2) (3) (4)

(1) (Reply) (Go Down)

How To Get Unknown Data That Has Been Displayed On A Page From Mysql Database by ebenz01: 4:33pm On Apr 10, 2015
helo guys. Pls i need help on a particular code. I need to pass some data whch were fetched from the database to another page for processng. The implication is that only the ones that are chosed through checkbox will be the ones to be passed for processing, to be inserted into database precisely. I use php. Pls help m o
Re: How To Get Unknown Data That Has Been Displayed On A Page From Mysql Database by elfico(m): 5:49pm On Apr 10, 2015
ebenz01:
helo guys. Pls i need help on a particular code. I need to pass some data whch were fetched from the database to another page for processng. The implication is that only the ones that are chosed through checkbox will be the ones to be passed for processing, to be inserted into database precisely. I use php. Pls help m o
you need state the challenge clearly. Or even show the code.
Re: How To Get Unknown Data That Has Been Displayed On A Page From Mysql Database by ebenz01: 6:03pm On Apr 10, 2015
ok. Wat im tryng to do is a school portal where students can register for courses? Now there are lists of courses which is peculiar to each class, nd every member of the class can choose the number of courses he wants out of the available courses for his class. What i did is to fetch available courses for a particular class from database having a checkbox beside each course. The student needs to check the courses he wants to register and then submit. The challenge is, since i dont knw the number of data that has been fetched or would be fetched, how do i pass them to the next page or how do i insert the checked ones back to the database
Re: How To Get Unknown Data That Has Been Displayed On A Page From Mysql Database by ace1(m): 6:44pm On Apr 10, 2015
ebenz01:
ok. Wat im tryng to do is a school portal where students can register for courses? Now there are lists of courses which is peculiar to each class, nd every member of the class can choose the number of courses he wants out of the available courses for his class. What i did is to fetch available courses for a particular class from database having a checkbox beside each course. The student needs to check the courses he wants to register and then submit. The challenge is, since i dont knw the number of data that has been fetched or would be fetched, how do i pass them to the next page or how do i insert the checked ones back to the database

http://stackoverflow.com/questions/4516847/make-array-from-checkbox-form

Guess this is close to what you want

1 Like

Re: How To Get Unknown Data That Has Been Displayed On A Page From Mysql Database by Nobody: 7:09pm On Apr 10, 2015
I wish I understand it challenge to help out. Maybe I could, here and now, I'm lost... totally.
Re: How To Get Unknown Data That Has Been Displayed On A Page From Mysql Database by kudaisi(m): 2:21am On Apr 14, 2015
Re: How To Get Unknown Data That Has Been Displayed On A Page From Mysql Database by kudaisi(m): 2:29am On Apr 14, 2015
I assume that the check box are bring represented as an array in the underlying html and can be accessed via one variable from the GET or POST variables. e.g
<form method='post' id='userform' action='thisform.php'> <tr>
<td>Trouble Type</td>
<td>
<input type='checkbox' name='checkboxvar[]' value='Option One'>1<br>
<input type='checkbox' name='checkboxvar[]' value='Option Two'>2<br>
<input type='checkbox' name='checkboxvar[]' value='Option Three'>3
</td> </tr> </table> <input type='submit' class='buttons'>
</form>
Now all you have to do from the PHP side of your code that will be updating the database is to loop through the checkboxvar[] array and add each element to the database.

Another key to the success of this design is you database structure. If I was to implement what you are trying to achieve i'll have the following tables: users, courses, user_course. Where users contains user info and courses contains each individual course. While the user_course will tie info regarding course in relation to a certain user.

Now while looping through the array for the check box you sql statement may look like this. INSERT INTO user_topic (id, user_id, course_id, course_status, source_date etc......user_id can be gotten from the actively logged in user session variable, while the course_id will be based on the course selected in the drop down list from the prior page. This was, for each entry in the loop you'll run the above sql statement against the database. Although the course_id will change for each check box value.

You php code will look something like this
$courses = $_POST['checkboxvar']
if (is_array($courses)){
$arrlength = count($courses);
for($x = 0; $x < $arrlength; $x++) {
mysql_query("INSERT INTO user_topic (id, user_id, course_id, course_status)"+
"VALUES(NULL,".$_SESSION['user_id'].", ".$courses[x].", ACTIVE)";
}
}else{
// If it is not an array then only one check box was checked. So run above mysql_query once
}
NOTE: The approach above is only for educational purpose and not to be used for production environment. Directly entering sql statements into mysql_query() is prone to SQL injection.
Re: How To Get Unknown Data That Has Been Displayed On A Page From Mysql Database by ebenz01: 7:05am On May 14, 2015
thnks for that @kudaisi. I fnd a solution to it. My challenge was giving a name to the check boxes cos i dnt knw exactly how many checkboxes..they are all coming from d database. But i finaly implemented an array for the naming, and then implemented a for each loop in getting the values before inserting into database. Another challenge i got was that the submit variable value is also inserting into the database....but i found a way arnd it by unseting the submit value just before inserting into database.
Thanks for d contrbution cos ive learnt something from it.

(1) (Reply)

simple ad Code / Nairaland Topic Re-direction Error / Software Testing In Africa - A New Community

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 24
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.