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>"; ?> Link to comment https://forums.phpfreaks.com/topic/213866-query-returns-nothing/ 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. Link to comment https://forums.phpfreaks.com/topic/213866-query-returns-nothing/#findComment-1113129 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. Link to comment https://forums.phpfreaks.com/topic/213866-query-returns-nothing/#findComment-1113131 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 Link to comment https://forums.phpfreaks.com/topic/213866-query-returns-nothing/#findComment-1113136 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.