unibox Posted March 11, 2010 Share Posted March 11, 2010 It's hard to ask this right for a noob. I am working on a scholarship website. I need to display a list of applicants for a specific scholarship for which they checked off in the form. They way the data is displayed now, all applicants names are orded by date DESC. Each name links to the full record. This works good. Now they want a new page to display the same way but only for a specific scholarship. I think what is throwing me is the "1 and 0" for checked and un-checked. I hope you can understand. I know what I need but it is hard to ask it so you can understand it. Thanks! Andy Link to comment https://forums.phpfreaks.com/topic/194905-get-the-result-from-a-check-box-and/ Share on other sites More sharing options...
unibox Posted March 11, 2010 Author Share Posted March 11, 2010 I thinkin.. Could I add a where statement in this like where Alumni=1 $result = mysql_query("SELECT * FROM scholarships ORDER BY datex DESC"); while($row = mysql_fetch_array($result)){ $applicant = $row['studentID']; echo " or something like if ($row[$Alumni] == 1) Link to comment https://forums.phpfreaks.com/topic/194905-get-the-result-from-a-check-box-and/#findComment-1024776 Share on other sites More sharing options...
XeNoMoRpH1030 Posted March 11, 2010 Share Posted March 11, 2010 If I understand you correctly, you have a form with several checkboxes which are all the scholarships. You check the specific ones you want to be included in the query? If you are retrieving them by an ID and the checkbox values correspond to those, it will be really easy, assuming the checkboxes are named the same in the HTML. PHP creates an array when input field names are the same. What you can do is $scholarships = (is_array($_POST['checkbox'])?implode(",",$_POST['checkbox']):$_POST['checkbox']); $result = mysql_query("SELECT * FROM scholarships WHERE id IN ($scholarships) ORDER BY datex DESC"); Of course, if nothing is checked, the query would fail. What it does it checks to see if $_POST['checkbox'] is an array. If so, it uses implode() which, in this case, makes a comma delimited string using the array. If it's not an array, just use the single value that was hopefully passed. The idea is that the IN clause would be either IN (2) if it's not an array, and IN (2,3,4,5,6) if it was. Hopefully, that is enough to get you in the right direction. Link to comment https://forums.phpfreaks.com/topic/194905-get-the-result-from-a-check-box-and/#findComment-1024780 Share on other sites More sharing options...
unibox Posted March 11, 2010 Author Share Posted March 11, 2010 Is there a way to make this more basic. Is there an easy way to display only the people who checked, say, the Alumni scholarship. Excuse my bad php but.. I need to dumb down. Like if Alumni=1 then continue on to display names.. I am donating my time to this non for profit scholarship organization to help them out. I feel bad just asking for answers instead of figuring it out my self but they have a 1 week deadline. I really appreciate your help. Thanks Link to comment https://forums.phpfreaks.com/topic/194905-get-the-result-from-a-check-box-and/#findComment-1024790 Share on other sites More sharing options...
XeNoMoRpH1030 Posted March 11, 2010 Share Posted March 11, 2010 I guess I didn't understand what you were asking and potentially still do not. The people who are checking the Alumni scholarship are people who are applying for it? If that's the case, I assume that would have been recorded in the database. Without seeing the structure, it would be difficult to come up with a specific solution, but a basic query would be like SELECT * FROM scholarships WHERE AlumniScholaryship = 1 ORDER BY datex DESC That is extremely basic and without a doubt won't work, but like I said, without knowing column names and such, it would be difficult to figure out the query. Is an HTML form being used to access this information? Link to comment https://forums.phpfreaks.com/topic/194905-get-the-result-from-a-check-box-and/#findComment-1024797 Share on other sites More sharing options...
unibox Posted March 11, 2010 Author Share Posted March 11, 2010 Cool that works! I just changed to my column name. Thanks! Link to comment https://forums.phpfreaks.com/topic/194905-get-the-result-from-a-check-box-and/#findComment-1024822 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.