RE: [PHP] PHP, JavaScript and populating DropDowns

2003-07-30 Thread Creative Solutions New Media
Thanks very much John.  It looks great.

Tim Winters
Manager, Creative Development
Sampling Technologies Incorporated (STI)
[EMAIL PROTECTED]
[EMAIL PROTECTED]
W: 902 450 5500
C:  902 430 8498

-Original Message-
From: John Manko [mailto:[EMAIL PROTECTED]
Sent: July 29, 2003 2:49 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED] Php. Net
Subject: Re: [PHP] PHP, JavaScript and populating DropDowns

assuming you have a table with colors, and each color has car associated
with it (yes, there might be dup color entries).
This should work (check spellings and case, etc..etc...)

$query="SELECT * from colors";
$results = mysql_query($query) or die ("DB ERROR:" . mysql_error());
$num = mysql_numrows($results);
$i=0;
echo "\n<!--\n";
while ($i < $num) {
echo "\n ca[$i] = new Array();";
echo "\n ca[$i][0] = \"" . mysql_result($results,$i,"CarID") . "\";";
echo "\n ca[$i][1] = \"" . mysql_result($results,$i,"ColorID") . "\";";
echo "\n ca[$i][2] = \"" . mysql_result($results,$i,"ColorName") .
"\";\n";
++$i;
}

echo "
function changeColor(ns)
{var SelectColor, NumEntries, i;

for (i = document.form1.selectcolor.length; i > 0; i--)
{
document.addform.selectcolor.options[i-1] = null;
}

document.form1.selectcolor.options[0] = new Option("-- Select Color
--",0);
len = 0;
if (ns != "0")
{
NumEntries = ca.length

for (i = 0; i < NumEntries; i++)
{
if(ca[i][0] == ns){
len++;
document.form1.selectcolor.options[len] = new
Option(ca[i][2],ca[i][1]);
}
}
}
document.form1.selectcolor.selectedIndex = 0;
}

";
echo "\n//-->\n\n";


this in later in the page...


$query="SELECT * from car";
$results = mysql_query($query) or die("ERROR - Please Contact Site
Administrator");
$num = mysql_numrows($results);
$i=0;
echo "Select Car";
while ($i < $num) {
  $id=mysql_result($results,$i,"CarID");
  $name=mysql_result($results,$i,"CarName");
 echo "$name";
  ++$i;
 }
echo "";


echo "-- Select Color
--";




---


Creative Solutions New Media wrote:

>Hello,
>
>I am using mySQL and PHP to pull some data into my page.
>
>I have 2 dropdown boxes.
>
>As an example lets say dropbox1 has a list of cars and dropbox2 has a list
>of colours.
>
>Here's the thing.  The colours for each car vary so I won't know what
>colours to populate the 2nd dropbox with until a car is chosen.  I really
>want this all contained on 1 page.
>
>Is there a standard way of dealing with this?  The only thing I can think
of
>is to reload the page once the make of car is selected which would give me
>the opportunity to populate the 2nd drop box at that time but that doesn't
>seem like a good solution.
>
>I don't know much in the way of JS but is there a way to do what I need
that
>way?
>
>Thanks.
>
>Tim Winters
>Manager, Creative Development
>Sampling Technologies Incorporated (STI)
>[EMAIL PROTECTED]
>[EMAIL PROTECTED]
>W: 902 450 5500
>C:  902 430 8498
>
>
>
>
>
>



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



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



Re: [PHP] PHP, JavaScript and populating DropDowns

2003-07-29 Thread John Manko
assuming you have a table with colors, and each color has car associated 
with it (yes, there might be dup color entries).
This should work (check spellings and case, etc..etc...)

$query="SELECT * from colors";
$results = mysql_query($query) or die ("DB ERROR:" . mysql_error());
$num = mysql_numrows($results);   
$i=0;
echo "\n\n\n";

this in later in the page...

$query="SELECT * from car";
$results = mysql_query($query) or die("ERROR - Please Contact Site 
Administrator");
$num = mysql_numrows($results);   
$i=0;
echo "Select Car";
while ($i < $num) {
 $id=mysql_result($results,$i,"CarID");
 $name=mysql_result($results,$i,"CarName");
echo "$name";
 ++$i;
}   
echo "";   

echo "-- Select Color 
--";



---

Creative Solutions New Media wrote:

Hello,

I am using mySQL and PHP to pull some data into my page.

I have 2 dropdown boxes.

As an example lets say dropbox1 has a list of cars and dropbox2 has a list
of colours.
Here's the thing.  The colours for each car vary so I won't know what
colours to populate the 2nd dropbox with until a car is chosen.  I really
want this all contained on 1 page.
Is there a standard way of dealing with this?  The only thing I can think of
is to reload the page once the make of car is selected which would give me
the opportunity to populate the 2nd drop box at that time but that doesn't
seem like a good solution.
I don't know much in the way of JS but is there a way to do what I need that
way?
Thanks.

Tim Winters
Manager, Creative Development
Sampling Technologies Incorporated (STI)
[EMAIL PROTECTED]
[EMAIL PROTECTED]
W: 902 450 5500
C:  902 430 8498


 



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


[PHP] PHP, JavaScript and populating DropDowns

2003-07-29 Thread Creative Solutions New Media
Hello,

I am using mySQL and PHP to pull some data into my page.

I have 2 dropdown boxes.

As an example lets say dropbox1 has a list of cars and dropbox2 has a list
of colours.

Here's the thing.  The colours for each car vary so I won't know what
colours to populate the 2nd dropbox with until a car is chosen.  I really
want this all contained on 1 page.

Is there a standard way of dealing with this?  The only thing I can think of
is to reload the page once the make of car is selected which would give me
the opportunity to populate the 2nd drop box at that time but that doesn't
seem like a good solution.

I don't know much in the way of JS but is there a way to do what I need that
way?

Thanks.

Tim Winters
Manager, Creative Development
Sampling Technologies Incorporated (STI)
[EMAIL PROTECTED]
[EMAIL PROTECTED]
W: 902 450 5500
C:  902 430 8498




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