chbrules Posted December 30, 2006 Share Posted December 30, 2006 So I created a MySQL query that works perfectly fine when I test it against my databases in MySQL Query Browser, but when I use the PHP mysql_query() function it just doesn't work, period. No errors, no nothing. This is part of a big project I'm doing for someone, but I just can't seem to figure out why it won't work. I suspect it has something to do with IFNULL():[code]SELECT inventory.id, inventory.name, IFNULL(inventory.count - shipments_inventory.count, inventory.count), inventory.bin, inventory.unit_value, inventory.donation_idFROM ss.inventoryLEFT JOIN shipments_inventoryON inventory.id = shipments_inventory.inventory_idORDER BY name DESCLIMIT 2000[/code] Link to comment https://forums.phpfreaks.com/topic/32260-solved-mysql-query-works-in-mysql-qb-but-not-php/ Share on other sites More sharing options...
.josh Posted December 30, 2006 Share Posted December 30, 2006 can you post the actual code you are trying to use the query in? Link to comment https://forums.phpfreaks.com/topic/32260-solved-mysql-query-works-in-mysql-qb-but-not-php/#findComment-149754 Share on other sites More sharing options...
Nhoj Posted December 30, 2006 Share Posted December 30, 2006 You would need to do something more than just select the items from the DB, try doing this..[code=php:0]$query = mysql_query('SELECT inventory.id, inventory.name, IFNULL(inventory.count - shipments_inventory.count, inventory.count), inventory.bin, inventory.unit_value, inventory.donation_idFROM ss.inventoryLEFT JOIN shipments_inventoryON inventory.id = shipments_inventory.inventory_idORDER BY name DESCLIMIT 2000');while ($inventory = mysql_fetch_assoc($query)) { echo $inventory['id'].' - '.$inventory['name'];}[/code] Link to comment https://forums.phpfreaks.com/topic/32260-solved-mysql-query-works-in-mysql-qb-but-not-php/#findComment-149755 Share on other sites More sharing options...
chbrules Posted December 30, 2006 Author Share Posted December 30, 2006 Well how come the select statement works just fine in MySQL QB and not through PHP's mysql extension? I use my other mysql queries with mysql_query() and mysql_result() all the time. I think I've only had this issue one other time and I just tossed the idea and made a less efficient thing. Link to comment https://forums.phpfreaks.com/topic/32260-solved-mysql-query-works-in-mysql-qb-but-not-php/#findComment-149779 Share on other sites More sharing options...
.josh Posted December 30, 2006 Share Posted December 30, 2006 again, post your code. Link to comment https://forums.phpfreaks.com/topic/32260-solved-mysql-query-works-in-mysql-qb-but-not-php/#findComment-149785 Share on other sites More sharing options...
chbrules Posted December 30, 2006 Author Share Posted December 30, 2006 Well I think a better way to go about this would be to ask this question:Say I have 2 tables, one of all inventory ever recieved, then another list of all inventory ever shipped out. Comparing both lists will give you the current inventory. Say I have this setup:Table 1 (inventory):idcountTable 2 (shipments inventory):idinventory_idcountAs you can see, when you ship inventory, it makes a new line in the database of which item shipped and how many. So you can see how it's comparative in that way.What I propose is how do I pull a list of all current inventory in stock? I have to do 2 comparisons, one of which items don't exist in the shipment table (no items ever shipped), and one of which compares how many are in stock to how many have actually shipped total (to see if that item is sold out). Maybe I'm just having a mind fart here, but maybe someone can help me out? Link to comment https://forums.phpfreaks.com/topic/32260-solved-mysql-query-works-in-mysql-qb-but-not-php/#findComment-149790 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.