widget Posted February 10, 2013 Share Posted February 10, 2013 Heres the setup Virtual pet site, users shop. They can click on an icon that will price their item 1 point less than the lowest existing. Trouble is, if no-one else has that item in stock, the icon prices the item the same price as the previous item listed. Example Chocolate Bar $1 Red Hat $1 <--- theres none of these in any other shop therefor it needs to return $0 Here is my code. $findResults = mysql_query("SELECT * FROM usershops_items2 WHERE price > '0' AND item_id = '$find_item2[id]' ORDER BY price ASC LIMIT 1"); while ($getResults = mysql_fetch_array($findResults)) { $cheap = $getResults[price]; $cheap2 = $cheap -1; } $cheap = "<span onclick=\"MM_setTextOfTextfield('item_price[$id]','','$cheap2')\"><img src=images/items/item_747.gif width=24 height=24></span>"; I have tried adding in if statements in different places but nothing works. Quote Link to comment https://forums.phpfreaks.com/topic/274282-if-no-result-display-0-in-table-results/ Share on other sites More sharing options...
Zane Posted February 10, 2013 Share Posted February 10, 2013 Could you elaborate a bit more? AKA, put more effort into your question? Quote Link to comment https://forums.phpfreaks.com/topic/274282-if-no-result-display-0-in-table-results/#findComment-1411474 Share on other sites More sharing options...
denno020 Posted February 10, 2013 Share Posted February 10, 2013 You can count the number of results with mysql_num_rows(). However that's deprecated now so I'm not sure what the alternative is.. Anyway, that will count the results, and if there are none, it will return false, which you can use in an if statement, before your while loop. Denno Quote Link to comment https://forums.phpfreaks.com/topic/274282-if-no-result-display-0-in-table-results/#findComment-1411478 Share on other sites More sharing options...
widget Posted February 10, 2013 Author Share Posted February 10, 2013 Sorry Zane There is a table of item a user has in their shop. They can click a button next to the pricing field in their shop that will set the price for them by searching the database of all users shops for that item, retrieving the cheapest price and setting their price $1 less. The trouble is, when it comes across an item that noone else has in stock it doesnt know what to do and simply just uses the previous items price. Quote Link to comment https://forums.phpfreaks.com/topic/274282-if-no-result-display-0-in-table-results/#findComment-1411487 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.