bdipasquale
asked on
numbers dont follow in select box when ordering sql statement
years do not follow in select box
data2 in my query contains letters or numbers which correspond to the year the car was built, thus the reason of my array, however my numbers dont come out right, I get
<select name='autoYear' class="textboxesAutoInfo"> <option value=''></option><option value='2001'>2001</option>
<option value='2002'>2002</option>
<option value='2003'>2003</option>
<option value='2004'>2004</option>
<option value='2005'>2005</option>
<option value='2006'>2006</option>
<option value='2007'>2007</option>
<option value='1994'>1994</option>
<option value='1995'>1995</option>
<option value='1996'>1996</option>
<option value='1997'>1997</option>
<option value='1998'>1998</option>
<option value='1999'>1999</option>
<option value='2000'>2000</option>
</select>
here is my code
$cbbYearArray = array("R","S","T","V","W", "X","Y","1 ","2","3", "4","5","6 ","7","8", "9");
$yearArray = array("1994","1995","1996" ,"1997","1 998","1999 ","2000"," 2001","200 2","2003", "2004","20 05","2006" ,"2007","2 008","2009 ");
$startYearString = "<select name='autoYear' class=\"textboxesAutoInfo\ "><option value=''></option>";
$getCBByearsQuery = mysql_query("SELECT DISTINCT(data2) FROM cbb WHERE data7='" . $makeOne . "' ORDER BY data2") or die();
while($getCBByearsResult = mysql_fetch_object($getCBB yearsQuery ))
{
for($i=0; $i <=15; $i++)
{
if($getCBByearsResult->dat a2 == $cbbYearArray[$i])
{
$startYearString .= "<option value='" . $yearArray[$i] . "'>" . $yearArray[$i] . "</option>";
}
}
}
$startYearString .= "</select>";
data2 in my query contains letters or numbers which correspond to the year the car was built, thus the reason of my array, however my numbers dont come out right, I get
<select name='autoYear' class="textboxesAutoInfo">
<option value='2002'>2002</option>
<option value='2003'>2003</option>
<option value='2004'>2004</option>
<option value='2005'>2005</option>
<option value='2006'>2006</option>
<option value='2007'>2007</option>
<option value='1994'>1994</option>
<option value='1995'>1995</option>
<option value='1996'>1996</option>
<option value='1997'>1997</option>
<option value='1998'>1998</option>
<option value='1999'>1999</option>
<option value='2000'>2000</option>
</select>
here is my code
$cbbYearArray = array("R","S","T","V","W",
$yearArray = array("1994","1995","1996"
$startYearString = "<select name='autoYear' class=\"textboxesAutoInfo\
$getCBByearsQuery = mysql_query("SELECT DISTINCT(data2) FROM cbb WHERE data7='" . $makeOne . "' ORDER BY data2") or die();
while($getCBByearsResult = mysql_fetch_object($getCBB
{
for($i=0; $i <=15; $i++)
{
if($getCBByearsResult->dat
{
$startYearString .= "<option value='" . $yearArray[$i] . "'>" . $yearArray[$i] . "</option>";
}
}
}
$startYearString .= "</select>";
ASKER
NO ITS BECAUSE ITS ORDERING NUMBERS BEFORE LETTERS, COULD CHANGE THIS ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sorry but the order in which the result in my select box are the same as before
notice it does follow
<select name='autoYear' class="textboxesAutoInfo"> <option value=''></option><option value='2001'>2001</option>
<option value='2002'>2002</option>
<option value='2003'>2003</option>
<option value='2004'>2004</option>
<option value='2005'>2005</option>
<option value='2006'>2006</option>
<option value='2007'>2007</option>
<option value='1994'>1994</option>
<option value='1995'>1995</option>
<option value='1996'>1996</option>
<option value='1997'>1997</option>
<option value='1998'>1998</option>
<option value='1999'>1999</option>
<option value='2000'>2000</option>
</select>
notice it does follow
<select name='autoYear' class="textboxesAutoInfo">
<option value='2002'>2002</option>
<option value='2003'>2003</option>
<option value='2004'>2004</option>
<option value='2005'>2005</option>
<option value='2006'>2006</option>
<option value='2007'>2007</option>
<option value='1994'>1994</option>
<option value='1995'>1995</option>
<option value='1996'>1996</option>
<option value='1997'>1997</option>
<option value='1998'>1998</option>
<option value='1999'>1999</option>
<option value='2000'>2000</option>
</select>
ASKER
a small little mod, and it worked
ASKER
$the_strings = array();
while($getCBByearsResult = mysql_fetch_object($getCBB yearsQuery ))
{
for($i=0; $i <=15; $i++)
{
if($getCBByearsResult->dat a2 == $cbbYearArray[$i])
$the_strings[$i] = "<option value='" . $yearArray[$i] . "'>" . $yearArray[$i] . "</option>";
}
}
$the_strings_sorted = array_unique ($the_strings) ;
for ($i=0; $i <=sizeof($the_strings_sort ed); $i++)
$startYearString .= $the_strings_sorted[$i];
$startYearString .= "</select>";
while($getCBByearsResult = mysql_fetch_object($getCBB
{
for($i=0; $i <=15; $i++)
{
if($getCBByearsResult->dat
$the_strings[$i] = "<option value='" . $yearArray[$i] . "'>" . $yearArray[$i] . "</option>";
}
}
$the_strings_sorted = array_unique ($the_strings) ;
for ($i=0; $i <=sizeof($the_strings_sort
$startYearString .= $the_strings_sorted[$i];
$startYearString .= "</select>";
Glad it works now, thx for the grade.
Rereading I would gusess that a more elegant rewriting might be
...
{
for($i=0; $i <=15; $i++)
{
if($getCBByearsResult->dat a2 == $cbbYearArray[$i])
$the_strings[] = "<option value='" . $yearArray[$i] . "'>" . $yearArray[$i] . "</option>";
}
}
$the_strings_sorted = array_unique ($the_strings) ;
foreach ({
for($i=0; $i <=15; $i++)
{
if($getCBByearsResult->dat a2 == $cbbYearArray[$i])
$the_strings[$i] = "<option value='" . $yearArray[$i] . "'>" . $yearArray[$i] . "</option>";
}
}
$the_strings_sorted = array_unique ($the_strings) ;
foreach ($the_strings_sorted as $i)
$startYearString .= $the_strings_sorted[$i];
)
$startYearString .= $the_strings_sorted[$i];
...
Rereading I would gusess that a more elegant rewriting might be
...
{
for($i=0; $i <=15; $i++)
{
if($getCBByearsResult->dat
$the_strings[] = "<option value='" . $yearArray[$i] . "'>" . $yearArray[$i] . "</option>";
}
}
$the_strings_sorted = array_unique ($the_strings) ;
foreach ({
for($i=0; $i <=15; $i++)
{
if($getCBByearsResult->dat
$the_strings[$i] = "<option value='" . $yearArray[$i] . "'>" . $yearArray[$i] . "</option>";
}
}
$the_strings_sorted = array_unique ($the_strings) ;
foreach ($the_strings_sorted as $i)
$startYearString .= $the_strings_sorted[$i];
)
$startYearString .= $the_strings_sorted[$i];
...
$getCBByearsQuery = mysql_query("SELECT DISTINCT(data2) as ddata2 FROM cbb WHERE data7='" . $makeOne . "' ORDER BY ddata2") or die();
Then you also need to replace your accesses of data2 with ddata2
or
$getCBByearsQuery = mysql_query("SELECT DISTINCT(data2) FROM cbb WHERE data7='" . $makeOne . "' ORDER BY 1") or die();