mizz key_me Posted September 25, 2008 Share Posted September 25, 2008 hye everyone..im a newbie here.. actually, i hav a project based on php and db.. i hav 2 submit it in 3 weeks time... the prob is..the more i've done the coding..the more i get soo confused.. ??? lets just be clear..im doing a project based on a school system.. the main thing is about the registration 4 new students.. example like i want 2 make the list 4 the staff 2 view bout the new students based on their gender... so i make this drop down menu consists of male and female..(of coz!! ) and the list will only view based on the gender that they choose... how do i code it so that my page will only appear the student list based on their gender.. plizz...i really need to understand it.. thanx alott.. Quote Link to comment https://forums.phpfreaks.com/topic/125808-help-me/ Share on other sites More sharing options...
F1Fan Posted September 25, 2008 Share Posted September 25, 2008 Post your code so we have something to work with. Quote Link to comment https://forums.phpfreaks.com/topic/125808-help-me/#findComment-650524 Share on other sites More sharing options...
mizz key_me Posted September 25, 2008 Author Share Posted September 25, 2008 <?php include 'db_connect.php'; $result = mysql_query("SELECT student_name, student_gender, student_regno FROM student WHERE class_no IS NULL"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { ?> u mean dis one?? :-\ Quote Link to comment https://forums.phpfreaks.com/topic/125808-help-me/#findComment-650530 Share on other sites More sharing options...
discomatt Posted September 25, 2008 Share Posted September 25, 2008 Just as a note... I'm not a grammar nazi, but this isn't an instant message or facebook. Reading through your description was pretty painful. When asking for help, please take the time to type out words completely and use proper grammar. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/125808-help-me/#findComment-650534 Share on other sites More sharing options...
JonnoTheDev Posted September 25, 2008 Share Posted September 25, 2008 example like i want 2 make the list 4 the staff 2 view The young text and instant messaging generation, painful! Quote Link to comment https://forums.phpfreaks.com/topic/125808-help-me/#findComment-650535 Share on other sites More sharing options...
mizz key_me Posted September 25, 2008 Author Share Posted September 25, 2008 When asking for help, please take the time to type out words completely and use proper grammar. Thanks. I'm really sorry... Its just me... I remember what my lecturer used to say.."To err is human. to forgive is divine." Sorry again.. Quote Link to comment https://forums.phpfreaks.com/topic/125808-help-me/#findComment-650543 Share on other sites More sharing options...
nadeemshafi9 Posted September 25, 2008 Share Posted September 25, 2008 hye everyone..im a newbie here.. actually, i hav a project based on php and db.. i hav 2 submit it in 3 weeks time... the prob is..the more i've done the coding..the more i get soo confused.. ??? lets just be clear..im doing a project based on a school system.. the main thing is about the registration 4 new students.. example like i want 2 make the list 4 the staff 2 view bout the new students based on their gender... so i make this drop down menu consists of male and female..(of coz!! ) and the list will only view based on the gender that they choose... how do i code it so that my page will only appear the student list based on their gender.. plizz...i really need to understand it.. thanx alott.. hey baby il help u, u see u need to do alot so do it bit by bit and tell us where u get stuck, 1. make the drop down menu (male female) and a submit button, the page must submit to itself so in teh form action writ ethe name of teh php file u are in 2. the page will submit to itself so it needs to know what has been submited at teh top of teh page when it sarts to load again so ask if u need to do this 3. when it knows that teh page has submited to itself it needs to then get a list of the males or females based on the input feild that has been posted $_post['gender'] and print it out sooooo just for you babs heres the code <?php include 'db_connect.php'; if($_post['gender']) { $result = mysql_query("SELECT student_name, student_gender, student_regno FROM student WHERE student_gender = '".$_POST['gender']."' "); while($row = mysql_fetch_array($result)){ echo $row['student_name']; echo $row['student_gender']; echo $row['student_regno']; { } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <select name="gender"> <option value="male">male</option> <option value="female">female</option> </select> <br> <br> <input type="submit" value="submit" name="submit"> </form> look in teh databse and see what teh values for gender are and modify <option value="male">male</option> <option value="female">female</option> it shoudl be ok anyways which uni do u go to ? Quote Link to comment https://forums.phpfreaks.com/topic/125808-help-me/#findComment-650544 Share on other sites More sharing options...
discomatt Posted September 25, 2008 Share Posted September 25, 2008 Here's some smaple code that should get you started. <?php # Check to see if the user has submitted the form if ( isset($_POST['gender']) ) { # Define gender as male/female depending on selection $gender = ( $_POST['gender'] == '1' ? 'female' : 'male' ); # Build your query $query = "SELECT `name` FROM `students` WHERE `gender` = '$gender'"; # Execute $result = mysql_query( $query ); # Echo results while( $data = mysql_fetch_assoc($result) ) echo $data['name'] . "<br />\n"; } ?> <br /><br /> <h3>What gender would you like to view?</h3> <form action="" method="post"> <input type="radio" name="gender" value="0" /> Male <br /> <input type="radio" name="gender" value="1" /> Female <br /><br /> <input type="submit" name="submit" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/125808-help-me/#findComment-650548 Share on other sites More sharing options...
nadeemshafi9 Posted September 25, 2008 Share Posted September 25, 2008 to make it look nicer change <?php echo $row['student_name']; echo $row['student_gender']; echo $row['student_regno']; to echo $row['student_name']."<br>"; echo $row['student_gender']."<br>"; echo $row['student_regno']."<br>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/125808-help-me/#findComment-650558 Share on other sites More sharing options...
mizz key_me Posted September 25, 2008 Author Share Posted September 25, 2008 thanx alot discomatt and nadeemshafi9 i've tried both codes but still cant preview it.. @nadeemshafi9: can u please tell me how to do it from the first step?? im really stuck.. :-\ besides, im studying in UiTM in Malaysia.. and you?? @discomatt: i've tried your codes. The table turns out perfectly but the data was not there... Thanx again.. Quote Link to comment https://forums.phpfreaks.com/topic/125808-help-me/#findComment-650565 Share on other sites More sharing options...
discomatt Posted September 25, 2008 Share Posted September 25, 2008 Mine won't 'just work'... you have to fill in your own database values. I'm not here to code for you, I'm here to help you. And just for the record, nadeemshafi9's code is wide open for injection. You're better off using 2 non-descriptive values ( I used 1 and 0 ) and replace with expect values manually. This will prevent any user input from being in the query. Also, thanks for replying in a slightly more formal manner I will help you further if you show your modified version of the example I provided. Quote Link to comment https://forums.phpfreaks.com/topic/125808-help-me/#findComment-650572 Share on other sites More sharing options...
mizz key_me Posted September 25, 2008 Author Share Posted September 25, 2008 @discomatt: i've already put the data in db...but i dont know why it does not appear in the table.. actually, for the registration report, i wanted to make 2 pages. First page: Select Gender ( I've made a drop down menu for gender ) Second page: The data of the new students will appear based on the gender that the staff choose. Quote Link to comment https://forums.phpfreaks.com/topic/125808-help-me/#findComment-650575 Share on other sites More sharing options...
discomatt Posted September 25, 2008 Share Posted September 25, 2008 As I said, show me your modified version of my code and I can help you further. I want to know you're at least making an effort Quote Link to comment https://forums.phpfreaks.com/topic/125808-help-me/#findComment-650599 Share on other sites More sharing options...
mizz key_me Posted September 25, 2008 Author Share Posted September 25, 2008 okay2..my mistake.. here's the code for the first page <form name="y1_gender" action="y1_report3.php" method="post"> <select name="gender"> <option value="Male">Male</option> <option value="Female">Female</option> </select> <br> <br> <input type="submit" value="submit" name="submit"> </form> and here's for the second page <?php include 'db_connect.php'; if($_post['gender']) { $result = mysql_query("SELECT student_name, student_gender, student_regno FROM student WHERE student_gender = $y1_gender "); while($row = mysql_fetch_array($result)){ echo $row['student_name']; echo $row['student_gender']; echo $row['student_regno']; { } ?> <tr> <td><?php echo "".$row['student_name'];?></td> <td><?php echo "".$row['student_gender'];?></td> <td><?php echo "".$row['student_regno'];?></td> <td><div align="center"><a href="s_detail.php?student_name=<?php echo $row['student_name']; ?>" class="style2">Detail</a></div></td> <td><div align="center"><a href="s_edit.php?student_name=<?php echo $row['student_name']; ?>" class="style2">Edit</a></div></td> <td><div align="center"><a href="s_delete.php?student_name=<?php echo $row['student_name']; ?>" class="style2">Delete</a></div></td> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/125808-help-me/#findComment-650606 Share on other sites More sharing options...
john-formby Posted September 25, 2008 Share Posted September 25, 2008 WHERE student_gender = $gender "); Quote Link to comment https://forums.phpfreaks.com/topic/125808-help-me/#findComment-650611 Share on other sites More sharing options...
discomatt Posted September 25, 2008 Share Posted September 25, 2008 it would appear that you're using nadeemshafi9's code... typos and all Quote Link to comment https://forums.phpfreaks.com/topic/125808-help-me/#findComment-650621 Share on other sites More sharing options...
john-formby Posted September 25, 2008 Share Posted September 25, 2008 WHERE student_gender = $gender "); Oops, just realised you are not storing the variable on the page. This should work: WHERE student_gender = '".$_POST['gender']."'"); Quote Link to comment https://forums.phpfreaks.com/topic/125808-help-me/#findComment-650629 Share on other sites More sharing options...
mizz key_me Posted September 25, 2008 Author Share Posted September 25, 2008 it would appear that you're using nadeemshafi9's code... typos and all it would appear that you're using nadeemshafi9's code... typos and all i'm sorry, here's the your code that i use <?php if ( isset($_POST['student_gender']) ) { $gender = ( $_POST['student_gender'] == '1' ? 'female' : 'male' ); $query = "SELECT `student_name, student_gender, student_regno FROM students WHERE gender = $gender"; $result = mysql_query( $query ); while( $data = mysql_fetch_assoc($result) ) echo $data['name'] . "<br />\n"; } ?> <tr> <td><?php echo "".$row['student_name'];?></td> <td><?php echo "".$row['student_gender'];?></td> <td><?php echo "".$row['student_regno'];?></td> <td><div align="center"><a href="s_detail.php?student_name=<?php echo $row['student_name']; ?>" class="style2">Detail</a></div></td> <td><div align="center"><a href="s_edit.php?student_name=<?php echo $row['student_name']; ?>" class="style2">Edit</a></div></td> <td><div align="center"><a href="s_delete.php?student_name=<?php echo $row['student_name']; ?>" class="style2">Delete</a></div></td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/125808-help-me/#findComment-650630 Share on other sites More sharing options...
discomatt Posted September 25, 2008 Share Posted September 25, 2008 Okay, first off... all string in MySQL must be enclosed in quotes $query = "SELECT student_name, student_gender, student_regno FROM students WHERE gender = '$gender' "; Second, look into WHILE http://php.net/manual/en/control-structures.while.php And learn how the WHILE loop works... then look into mysql_fetch_assoc() http://php.net/manual/en/function.mysql-fetch-assoc.php And learn how that function works. There's an example similar to what you want in that page. Read it up, give it another shot and let me know how you're doing. Quote Link to comment https://forums.phpfreaks.com/topic/125808-help-me/#findComment-650641 Share on other sites More sharing options...
nadeemshafi9 Posted September 29, 2008 Share Posted September 29, 2008 Mine won't 'just work'... you have to fill in your own database values. I'm not here to code for you, I'm here to help you. And just for the record, nadeemshafi9's code is wide open for injection. You're better off using 2 non-descriptive values ( I used 1 and 0 ) and replace with expect values manually. This will prevent any user input from being in the query. Also, thanks for replying in a slightly more formal manner I will help you further if you show your modified version of the example I provided. i dont think it matters if its unsafe code lol Quote Link to comment https://forums.phpfreaks.com/topic/125808-help-me/#findComment-652823 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.