hi, i have a database which stores my module names, exams in that module and my marks for that exams. in the index page of my website, it shows the names of my modules as links and when i follow that links, it show detailed info like module name, exam type and my marks
i have added several records to the database and there was several exam types for one module.
in the index page, it is showing one module for several times.
for example, i've added three exams in one module called BIS
in the index page it is showing BIS BIS BIS as links.
however, i want to display the module name only once, and when it is clicked, it will show all the exam types and my marks in that module.
would be great if someone could help
thanx
Display MySQL data
Moderator: General Moderators
Re: Display MySQL data
You should post your code.
it would be easier to understand what you need, and to help you.
it would be easier to understand what you need, and to help you.
Re: Display MySQL data
here is my code
ex.html
exam.php
you can also visit this http://smileboy07.comuf.com/ex.html
that's where those codes are used
ex.html
Code: Select all
<html>
<head>
</head>
<link href="layout.css" rel="stylesheet" type="text/css">
<body>
<div id="wrapper">
<div id="header">
</div>
<div id="navigation">navigation</div>
<div id="leftcolumn">leftcol</div>
<div id="content">
<?PHP
$connection = mysql_connect("mysql5.000webhost.com", "a7914385_akmal", "smileboy07") or die(mysql_error());
mysql_select_db("a7914385_test") or die(mysql_error());
$getExams = "SELECT * FROM exam";
$getExams_q = mysql_query($getExams, $connection);
while($getExams_r = mysql_fetch_assoc($getExams_q)) {
?>
<a href="exam.php?id=<?PHP echo $getExams_r['exam_id']; ?>"><?PHP echo $getExams_r['module_name']; ?></a>
<?PHP } ?>
</div>
<div id="footer">footer</div>
</div>
</body>
</html>
Code: Select all
<?PHP
$connection = mysql_connect("mysql5.000webhost.com", "a7914385_akmal", "smileboy07") or die(mysql_error());
mysql_select_db("a7914385_test") or die(mysql_error());
$getExams = "SELECT * FROM exam WHERE exam_id = '".mysql_real_escape_string($_GET['id'])."'";
$getExams_q = mysql_query($getExams, $connection);
$getExams_r = mysql_fetch_assoc($getExams_q);{
echo "Module Name:".$getExams_r['module_name']."<br />Exam Type:".$getExams_r['exam_type']."<br />My Marks:".$getExams_r['my_marks']."<br />";
}
?>
that's where those codes are used
Re: Display MySQL data
please dont post mysql usernames and passwords in the forum.. they will be open to public..
Re: Display MySQL data
it doesn't. it says " BDA BIS RAD BIS ".smileboy wrote:in the index page it is showing BIS BIS BIS as links.
maybe you have solved it. if you haven't changed your username/password, we can change your exam results
Re: Display MySQL data
well, anyway if you paid attention, it is showing BIS two times.('cuz i've entered two exams in that module) BDA BIS RAD BIS
what i want is to display it (as well as other modules) only once and when it is clicked, it should show all two exams in one page
what i want is to display it (as well as other modules) only once and when it is clicked, it should show all two exams in one page
Re: Display MySQL data
The reason why it listing it multiple times is because your telling it to in your code. You are doing a "SELECT *" then a WHILE loop so every record it finds you outputting them to the webpage.# $getExams = "SELECT * FROM exam";
# $getExams_q = mysql_query($getExams, $connection);
# while($getExams_r = mysql_fetch_assoc($getExams_q)) {
# ?>
# <a href="exam.php?id=<?PHP echo $getExams_r['exam_id']; ?>"><?PHP echo $getExams_r['module_name']; ?></a>
# <?PHP } ?>
In would be easier to rewrite/rework what you have instead of trying to write the logic to fix the code you have now.
These are only my suggestions but i would start with the following,
1. put your database connections in a separate file an include that file this will make it more secure.
2. separate you database to have modules in its own table and have a unique identifier (ex: auto incrementing number) and your exams with the scores in another table.
Here is a quick example of something i would of done In the example i'll assume i have two tables modules and exams. On the main page i'll list the module names with a link to the exam page where the exams will be listed.
// main page
<?php
include_once('db.php');
$result = mysql_query("SELECT moduleId, moduleName FROM module");
while(list($moduleId, $moduleName) = mysql_fetch_array($result)){
echo '<a href="yourwebsite.com?module=' + $moduleId + '">" + $moduleName +"</a><br />";
}
?>
//exam page after link is clicked
<?php
include_once('db.php');
//grab the module id from the url
if (isset($_GET['moduleId']){
$mId = $_GET['moduleId'];
}
$result = mysql_query("Select type, scores From exam where examId = $mId");
while(list($type, $scores) = mysql_fetch_array($result)){
echo $type + '>>>>>' $scores '<br/ >';
}
?>
Now this is only a quick and dirty example its the best i could come up with this late in the evening.
Matthew Vass
QA Analyst
mvass@hostmysite.com
http://www.hostmysite.com?utm_source=bb
Re: Display MySQL data
i pay attention very well and that's not what you wrote, but never mind, it's best you rethink the whole logic as suggested.smileboy wrote:well, anyway if you paid attention, it is showing BIS two times.('cuz i've entered two exams in that module) BDA BIS RAD BIS
what i want is to display it (as well as other modules) only once and when it is clicked, it should show all two exams in one page
smileboy wrote: in the index page, it is showing one module for several times.
for example, i've added three exams in one module called BIS
in the index page it is showing BIS BIS BIS as links.