travelkind Posted January 6, 2010 Share Posted January 6, 2010 I need my php script to read a mysql table "rawdata" and return a field in it if the following criteria is met: 'supplier' field is equal to "SU" and 'terminal' field is equal to "GT" and 'product' field is equal to "UL LS DIESEL" and 'bub' field is equal to to "B" If all this criteria is met than return from the "rawdata" table the 'price' field. If all the conditions are not met than return "0.00" Any input would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/187466-php-to-read-mysql-table/ Share on other sites More sharing options...
zq29 Posted January 6, 2010 Share Posted January 6, 2010 Example: mysql_query("SELECT `field` FROM `table` WHERE `foo`='bar' AND `bar`='foo'"); Quote Link to comment https://forums.phpfreaks.com/topic/187466-php-to-read-mysql-table/#findComment-989879 Share on other sites More sharing options...
Maq Posted January 6, 2010 Share Posted January 6, 2010 Any input would be greatly appreciated. I'd recommend making an attempt for yourself. You're fortunate SA has given you an example. You can lookup syntax and definitions here: http://www.mysql.com/ We don't mind helping, but we don't like giving you direct answers, to what seems to be, a HW assignment. Quote Link to comment https://forums.phpfreaks.com/topic/187466-php-to-read-mysql-table/#findComment-989908 Share on other sites More sharing options...
travelkind Posted January 6, 2010 Author Share Posted January 6, 2010 Okay this is the code I used: mysql_query("SELECT `price` FROM `rawdata` WHERE `supplier`='SU' AND `terminal`='GT' AND `product`='UL LS DIESEL' AND `bub`='B'"); echo $row['price']; It returned data from the `price` field but it just grabbed the first entry in the table and didn't specifically follow the conditions I outlined. Where did I go wrong? Quote Link to comment https://forums.phpfreaks.com/topic/187466-php-to-read-mysql-table/#findComment-989928 Share on other sites More sharing options...
travelkind Posted January 6, 2010 Author Share Posted January 6, 2010 Okay I got it figured out. Thanks again everyone for your help. Quote Link to comment https://forums.phpfreaks.com/topic/187466-php-to-read-mysql-table/#findComment-989989 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.