Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MYSQL returns nothing after a space

Status
Not open for further replies.

winston1984

IS-IT--Management
Jun 4, 2004
17
0
0
GB
I have a piece fo code (below) which lists all the brands from a mySQL database. However, one of the brands has a space it it, it is '4 STAR', it only returns the '4', not the 'STAR', why is this? It is stored as varchar in the database.

<?
if ($currGroup != '') {
$query = "SELECT DISTINCT Products.ProdBrand FROM ProdCat INNER JOIN ProdGroup ON ProdCat.CatCode = ProdGroup.CatCode AND ProdCat.CatCode = ProdGroup.CatCode INNER JOIN Products ON ProdGroup.DeptID = Products.Department WHERE (ProdCat.CatCode = '".$currGroup."' ORDER BY ProdBrand";

} else {
$query = "SELECT DISTINCT(ProdBrand) FROM Products ORDER BY ProdBrand";

};
$result = mysql_query($query);

while ($row = mysql_fetch_array($result)) {
$item = $row['ProdBrand'];
if ($item == $currBrand) {
echo "<option value='".$item."' selected>".$row['ProdBrand']."</option>";

} else {
echo "<option value=".$item.">".$row['ProdBrand']."</option>";
}
}
?>

Help please...
 
It can be because you haven't placed a single quote surrounding $item in your else part.

Code:
while ($row = mysql_fetch_array($result)) {
    $item = $row['ProdBrand'];
    if ($item == $currBrand) {
                        echo "<option value='".$item."' selected>".$row['ProdBrand']."</option>";

    } else {
                        echo "<option value=[b]'[/b]".$item."[b]'[/b]>".$row['ProdBrand']."</option>";
    }
}

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top