Help - Search - Members - Calendar
Full Version: registered users - how to view registrants?
Hostony Board > General Support > PHP/MySQL
blackburnrovers
I am using Dreamweaver to create and display recordsets:

I created a registration page for students to choose courses. Their data gets stored in a regular table in MySQL DB.

I then created an administrative page which lists all the students by grade. There is a recordset for each grade, and then it lists the students' names. Each name is linked to a page called grade10student.php, and it passes their ID variable which lets the next page just be their information. Those pages work great, and just show individual student information.

The problem I am running in to is how to create a page for each class i.e. how do i see each student who registered for Algebra 1, or French I? Do i have to create a unique page for each of those classes?

The ideal option I suppose would be to create a page called class_details.php where a parameter was passed such as 8math=Algebra I, and then filter results where only students who selected Algebra I for 8math would display.

Any ideas would be much appreciated.
MartinB
I don't know anything of Dreamweaver and how are you doing recordsets with an html editor, but, why you can't do the follow ? :
QUOTE(blackburnrovers @ Apr 25 2005, 03:40 PM)
The ideal option I suppose would be to create a page called class_details.php where a parameter was passed such as 8math=Algebra I, and then filter results where only students who selected Algebra I for 8math would display.

*
blackburnrovers
QUOTE(mblendinger @ Apr 25 2005, 03:31 PM)
I don't know anything of Dreamweaver and how are you doing recordsets with an html editor, but, why you can't do the follow ? :
*


well, the problem is that in Dreamweaver (and maybe it is just because I am not handcoding the php) is that if I set up a page called course_details.php, I need a pass variables letting the new recordset match a particular column in the DB table. In the recordset definition however, I have to preselect the DB column. Basically I need to know how to use Dreamweaver (or something else) to create the recordset selecting the column based on the passed parameter from a previous page (example: column).

Does this make any sense?
MartinB
Do you want to know how to write a specific sql query for your schema?
blackburnrovers
What I believe would help is if I could use a variable in the SELECT statment. The select statement might be something like:
SELECT `first`, `last`, VARIABLE, id FROM registrationTable WHERE VARIABLE = (somehow take a parameter passed from the last page) remembering where VARIABLE is not a value, but the name of a column.
MartinB
If I understand you well(sorry my poor english), you want know how to read a GET or POST variable in php ?

If you pass the variable trought POST method:

CODE
$sqlQuery = 'SELECT first, last, '.$_POST['VARIABLE'].', id FROM registrationTable WHERE '.$_POST['VARIABLE'].' = "x"';



If you pass the variable trought GET method:

CODE
$sqlQuery = 'SELECT first, last, '.$_GET['VARIABLE'].', id FROM registrationTable WHERE '.$_GET['VARIABLE'].' = "x"';
blackburnrovers
When i try to use your line for
CODE
'.$_GET['VARIABLE'].'
, I get the following error message:
QUOTE
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING


It seems to not parse that entry properly. I tried putting the $_GET in {} as well, but that didn't work. I am trying to basically ask it to filter WHERE column_name_variable = course_name.
Niakie
If the variable has a single quote in it then it will break that line... You have to test the verrable first and parse the quotes before passing it to the string..
MartinB
CODE
$sqlQuery = 'SELECT first, last, '.$_GET["VARIABLE"].', id FROM registrationTable WHERE '.$_GET['VARIABLE'].' = "x"';


it's working good here sad.gif
check your syntaxis, put attention tu the '
MartinB
QUOTE(Niakie @ Apr 26 2005, 02:14 PM)
If the variable has a single quote in it then it will break that line... You have to test the verrable first and parse the quotes before passing it to the string..
*


good point.

blackburnrovers:
Make sure than the value of the variable don't have single quotes (is only a name of a column, or not ?)
blackburnrovers
CODE
$query_Recordset1 = sprintf("SELECT `first`, `last`, ".$_GET["course"].", `id` FROM registration0506
WHERE ".$_GET["course"]." = ".$_GET['coursename']."", $colname_Recordset1);


ok, this is the code. part made by me, part made my dreamweaver.

you can see that i want to get the data stored in first, last, id, and also for a 4th column which i want to pull from the $_GET["course"].

Then, I want it to use the WHERE statement to only show students who match the particular coursename. In my example, the course (name of column) might be 8math and the coursename would be AlgebraI.

With the current code, I get the following error passing the course=8math and coursname=AlgebraI parameters: "Unknown column 'AdvancedAlgebraI' in 'where clause'"

It seems that it is trying to use the coursename for the DB column name instead of comparing it to the values inside the column name.

Thanks to all for their help.
MartinB
the follow may work:

CODE
$query_Recordset1 = sprintf('SELECT first, last, '.$_GET['course'].', id FROM registration0506
WHERE '.$_GET['course'].' = '.$_GET['coursename'], $colname_Recordset1);


why are you using sprintf ?
why not just:

CODE
$query_Recordset1 = 'SELECT first, last, '.$_GET['course'].', id FROM registration0506
WHERE '.$_GET['course'].' = '.$_GET['coursename'];
Niakie
you need to put single quotes around strings or else it will presume that you are reffering to a colum. Try this:

CODE
$query_Recordset1 = sprintf("SELECT `first`, `last`, ".$_GET["course"].", `id` FROM registration0506 WHERE ".$_GET["course"]." = '".$_GET['coursename']."'", $colname_Recordset1);
MartinB
you're right, sorry:

CODE
$query_Recordset1 = sprintf('SELECT first, last, '.$_GET['course'].', id FROM registration0506
WHERE '.$_GET['course'].' = "'.$_GET['coursename'].'"', $colname_Recordset1);
blackburnrovers
thank you both so much for your help. your code tweaks worked perfectly. the sprintf was a remnant of trying to use dreamweaver's sql wizard. i don't know much sql code so am not even sure what it does. at this point, i am not going to mess with it since everything is working.

thanks again, you saved me the hassle of creating about 50 more pages by being able to make this one page dynamically.
MartinB
You're welcome, blackburnrovers smile.gif Welcome to dynamic world, I think than you'll never do static pages again wink.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.
IPS Driver Error

IPS Driver Error

There appears to be an error with the database.
You can try to refresh the page by clicking here