Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Course Queries Syllabus Queries 2 years ago
Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
Hello i am new to php and i have tried to find a piece of code that i can use to complete the task i need, i currently have a page with a form set out to view the criteria of a course. also i have a dropdown menu which currently holds all the course codes for the modules i have stored in a database. my problem is when i select a course code i wish to populate the fields in my form to show all the information about the course selected. The code i am trying to get to work is as follows:
php session_start(); ?> include ("dbcon.php") ?> php if(!isset($_GET['coursecode'])){ $Var ='%'; } else { if($_GET['coursecode'] == "ALL"){ $Var = '%'; } else { $Var = $_GET['coursecode']; } } echo "method=\"GET\"> Coursecode"; $res=mysql_query("SELECT * FROM module GROUP BY mId"); if(mysql_num_rows($res)==0){ echo "there is no data in table.."; } else { echo " ALL "; for($i=0;$i<mysql_num_rows($res);$i++) { $row=mysql_fetch_assoc($res); echo"; if($Var==$row[coursecode]) echo " selected"; echo ">$row[coursecode]"; } echo ""; } echo "type=\"submit\" value=\"SELECT\" /> "; $query = "SELECT * FROM module WHERE coursecode LIKE '$Var' "; $result = mysql_query($query) or die("Error: " . mysql_error()); if(mysql_num_rows($result) == 0){ echo("No modules match your currently selected coursecode. Please try another coursecode!"); } ELSE { Coursecode: echo $row['coursecode']; Module: echo $row['mName']; echo $row['mCredits']; echo $row['TotalContactHours']; echo $row['mdescription']; echo $row['Syllabus']; } ?>
however i can only seem to get the last entry from my database any help to fix this problem or a better way of coding this so it works would be grateful
Thanks
The main error is in your final query, you're not actually fetching anything from the query, so you're just displaying the LAST row you fetched in the first query.
Some tips:
1) Don't use a for() loop to fetch results from a query result. While loops are far more concise:
$result = mysql_query(...) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { ... }
2) Add another one of these while loops to your final query, since it's just being executed, but not fetched.
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
Course Queries 4 Answers
Course Queries 5 Answers
Course Queries 1 Answers
Course Queries 3 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.