Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/274282-if-no-result-display-0-in-table-results/
Share on other sites

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.