Re: [PHP-DB] php, javascript and db - your help is needed

2004-07-19 Thread Nilo César Teixeira
Hi Cohen,

It´s really trivial. You show put a block that tests if a student is
selected, like

? if  (strlen($_REQUEST[student_id])0) { ?
DO SOME STUFF

SCRIPT
/* And add this simple feature to select the student passed as parameter */
/* Assuming that the select is inside a form named 'f' */
function selectOption(selectName, value) {
  var s =  document.f.elements[selectName];
  var found = false;
  for (var i=0; is.options.length  !found; i++) {
if (s.options[i].value==value) {
  s.selectedIndex=i;
  found = true;
}
  }
}

selectOption('student_id',?=$_REQUEST[student_id]?);
/SCRIPT
? } ?
- Original Message - 
From: G. Cohen [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Sunday, July 18, 2004 1:30 PM
Subject: [PHP-DB] php, javascript and db - your help is needed


 Hello,

 I have a HTML form with 2 select boxes, lets say students and courses.
When
 the from loads for the first time, I fill the students select box with
data
 from database. The courses selectbox remains empty.
 When the user selects a value from the students selectbox (onchange
event),
 I should go to the db to reterive the courses for the selected student and
 fill the courses selectbaox. I found it very complicated to do the
 interaction between javascript and php: apparently, I have to submit the
 from for the selected student id to be passed as a parameter to php (so
that
 php can access the db with the student id and retrieve his courses), and
at
 the same time I want the form to stay with the list of students, and the
 selected student. This should not be that hard, should it?! this is
 something trivial, I hope?
 I also tried using cookies, with no success.
 If someone knows how to do that, please let me know.

 Best Regards,
 G. Cohen

 -- 
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] php, javascript and db - your help is needed

2004-07-18 Thread G. Cohen
Hello,

I have a HTML form with 2 select boxes, lets say students and courses. When
the from loads for the first time, I fill the students select box with data
from database. The courses selectbox remains empty.
When the user selects a value from the students selectbox (onchange event),
I should go to the db to reterive the courses for the selected student and
fill the courses selectbaox. I found it very complicated to do the
interaction between javascript and php: apparently, I have to submit the
from for the selected student id to be passed as a parameter to php (so that
php can access the db with the student id and retrieve his courses), and at
the same time I want the form to stay with the list of students, and the
selected student. This should not be that hard, should it?! this is
something trivial, I hope?
I also tried using cookies, with no success.
If someone knows how to do that, please let me know.

Best Regards,
G. Cohen

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] php, javascript and db - your help is needed

2004-07-18 Thread Marcjon
You could use a if/while construct. Something like:

select name=\courses\
?php
if ($_POST['studentselect']){
$result = mysql_query(SELECT courses FROM students WHERE student_name =
' . $_POST['studentselect'] . ');

while ($row = mysql_fetch_assoc($result))
{
echo option value=.$row['course']..$row['course']./option;
}
}
?
/select

Basically you would submit the form, and if a student was selected, it
would populate the list with their courses from the database.

-- 
  Marcjon

- Original message -
From: G. Cohen [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Date: Sun, 18 Jul 2004 19:30:49 +0300
Subject: [PHP-DB] php, javascript and db - your help is needed

Hello,

I have a HTML form with 2 select boxes, lets say students and courses.
When
the from loads for the first time, I fill the students select box with
data
from database. The courses selectbox remains empty.
When the user selects a value from the students selectbox (onchange
event),
I should go to the db to reterive the courses for the selected student
and
fill the courses selectbaox. I found it very complicated to do the
interaction between javascript and php: apparently, I have to submit the
from for the selected student id to be passed as a parameter to php (so
that
php can access the db with the student id and retrieve his courses), and
at
the same time I want the form to stay with the list of students, and the
selected student. This should not be that hard, should it?! this is
something trivial, I hope?
I also tried using cookies, with no success.
If someone knows how to do that, please let me know.

Best Regards,
G. Cohen

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] php, javascript and db - your help is needed

2004-07-18 Thread Justin Patrin
On Sun, 18 Jul 2004 13:24:01 -0700, Marcjon [EMAIL PROTECTED] wrote:
 You could use a if/while construct. Something like:
 
 select name=\courses\
 ?php
 if ($_POST['studentselect']){
 $result = mysql_query(SELECT courses FROM students WHERE student_name =
 ' . $_POST['studentselect'] . ');
 
 while ($row = mysql_fetch_assoc($result))
 {
 echo option value=.$row['course']..$row['course']./option;
 }
 }
 ?
 /select
 
 Basically you would submit the form, and if a student was selected, it
 would populate the list with their courses from the database.
 
 --
   Marcjon
 
 
 
 - Original message -
 From: G. Cohen [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Date: Sun, 18 Jul 2004 19:30:49 +0300
 Subject: [PHP-DB] php, javascript and db - your help is needed
 
 Hello,
 
 I have a HTML form with 2 select boxes, lets say students and courses.
 When
 the from loads for the first time, I fill the students select box with
 data
 from database. The courses selectbox remains empty.
 When the user selects a value from the students selectbox (onchange
 event),
 I should go to the db to reterive the courses for the selected student
 and
 fill the courses selectbaox. I found it very complicated to do the
 interaction between javascript and php: apparently, I have to submit the
 from for the selected student id to be passed as a parameter to php (so
 that
 php can access the db with the student id and retrieve his courses), and
 at
 the same time I want the form to stay with the list of students, and the
 selected student. This should not be that hard, should it?! this is
 something trivial, I hope?
 I also tried using cookies, with no success.
 If someone knows how to do that, please let me know.
 
 Best Regards,
 G. Cohen
 

PHP is a server-side language, so any further processing can only be
done when the browser sends a new request. You have to refresh *some*
page to get new data.

It is possible to use a hidden iframe to send a request, then parse it
with JS and display it in the main page, but this isn't trivial.

-- 
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder

paperCrane --Justin Patrin--

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php