esandra Posted September 20, 2010 Share Posted September 20, 2010 this is supposed to display the distinct first two characters of a string(billnmbr) in a combobox ive tried this on phpmyadmin and it returns 08.. which is correct when i run this on my server, it returns nothing.. there must be something wrong with the way i called the billnmbr does anybody have an idea on how i could call and display this correctly? thanks and have a nice day. <?php $mquery = "select distinct(substring(`billnmbr`, 1, 2)) from `tbltest`"; $mres =mysql_query($mquery) or die(mysql_error()); while($mrow=mysql_fetch_array($mres)){ $mm = $mrow['billnmbr']; echo "<option value=" . $mrow['billnmbr'] . ">"; echo $mrow['billnmbr'] . "</option>"; } echo " </select>"; ?> Quote Link to comment Share on other sites More sharing options...
colleyboy Posted September 20, 2010 Share Posted September 20, 2010 I think theres an unassigned variable. $mm = $mrow['billnmbr']; echo "<option value=" . $mrow['billnmbr'] . ">"; what is $mm ? You cant assign a variable to an unassigned variable because it would be zero... hence it not showing anything. Quote Link to comment Share on other sites More sharing options...
the182guy Posted September 20, 2010 Share Posted September 20, 2010 Change the query to $mquery = "select distinct(substring(`billnmbr`, 1, 2)) AS billnmbr from `tbltest`"; What's happening is the field is being returned but it wasn't called bullnmbr, it was called substring(`billnmbr`, 1, 2) Use the AS syntax to give that a friendly name. Quote Link to comment Share on other sites More sharing options...
esandra Posted September 20, 2010 Author Share Posted September 20, 2010 "AS" solves it. Thank you very much for the help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.