substr from query
Posted: Tue Jan 06, 2004 11:19 pm
hello all gurus...
i have a problem with the substr function..
firstly i wanna tell that i'm a newbie in php..
now i describe my problem...
i have a combobox whick the lists i load up from mysql database...
the list contains ID such as B01,E01 and D01...
i call all these ID's Major ID...
There are another ID's such as B02,B03,E02,E03,D02 and D03 which i call Minor ID...
all wanna do is when a user select the major ID from the first combobox(Major ID) then PHP automatically recognize the first letter (let say the first letter from B01 is B) and then load up the the second combobox (Minor ID) with ID that only started with B....(do u understand?i'm sorry..my english is pretty bad...
for reference,i enclose here my silly code snippets:
pls help me.........
i have a problem with the substr function..
firstly i wanna tell that i'm a newbie in php..
now i describe my problem...
i have a combobox whick the lists i load up from mysql database...
the list contains ID such as B01,E01 and D01...
i call all these ID's Major ID...
There are another ID's such as B02,B03,E02,E03,D02 and D03 which i call Minor ID...
all wanna do is when a user select the major ID from the first combobox(Major ID) then PHP automatically recognize the first letter (let say the first letter from B01 is B) and then load up the the second combobox (Minor ID) with ID that only started with B....(do u understand?i'm sorry..my english is pretty bad...
for reference,i enclose here my silly code snippets:
Code: Select all
<select name="noTag" size="1">
<option value="0">Choose Major ID </option>
<?php
//----------------------------------------------------
// Access Data From MySQL
// TABLE : tPartMajor
//----------------------------------------------------
$query2 = "Select * from ".$DBprefix."tPartMajor";
$mesin = mysql_query($query2);
while ($dbq = mysql_fetch_array($mesin)) {
echo("<OPTION VALUE=$dbqїidMajor] selected>$dbqїidMajor]</option>\n");
$front=substr($dbqїidMajor],0);
}
?>
</select>
</td>
</tr>
<tr>
<td valign="top" height="27"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>ID
Minor:</b></font></td>
<td valign="top">
<select name="noTag2" size="1">
<option value="0">Choose Minor ID</option>
<?php
//----------------------------------------------------
// Access Data From MySQL
// TABLE : tPartMinor
//----------------------------------------------------
$query2 = "Select * from ".$DBprefix." tPartMinor where substring(idMinor,0)='$front'";
$mesin = mysql_query($query2);
while ($dbq = mysql_fetch_array($mesin)) {
echo("<OPTION VALUE=$dbqїidMinor] selected>$dbqїidMinor]</option>\n");
}
?>
</select>pls help me.........