Jump to content

Recommended Posts

I'm a total newbie to php and desperatley need help. Searched forums but couldnt find the answer.

 

I have a price field (integer) and if it's $0, then I dont want it to display at all. It should only display if its >0.

 

At this time if the price is $0 in the database, the page displays $0 and I want it to show nothing.

 

My code...

 

<?php

$result = mysql_query("SELECT breedingprice FROM animals WHERE (animals.ari=123076)");

$fresult=(mysql_result($result,0));

$newresult=(number_format($fresult,0));

printf($sign.$newresult,0);

?>

 

any help will be forever appreciated!!!

 

I know this is more or less solved, but Just to add to this and explain ....

 

it should be >1 ( as stated above ) not >0  .... ">" means greater than or equal to. So this means if the price is 0 this is equal to 0 and therefore it will show a price.

Well guys I am very impressed with the speed of your replies and thanks also.

 

I replaced the code as stated and now am getting the following error on the page..

 

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 19 in /home/lcalpaca/public_html/animals/incatest.php on line 146

 

...

That means that you didn't get any rows returned. A much better way of writing this would be:

<?php
$query = "SELECT breedingprice FROM animals WHERE breedingprice >= 1 AND animals.ari=123076";
$result = mysql_query($query) or die("Problem with the query <pre>$query</pre><br>" . mysql_error());
if (mysql_num_rows > 0) {
   $rw = mysql_fetch_assoc($result);
   echo $sign . number_format($rw['breedingprice']);
}
?>

 

Ken

Tried that Ken and the result is that with the field 'breedingprice' populated with an amount such as '5000' or with '0' or with NULL, nothing displays on the page (the dollar sign also is not displayed).

 

Seems like it should work. Could it have something to do with the field type in the database? This field is set to...

integer

nulls are allowed

default value is null

 

This is my opening code at the start of the page...

 

<?php -

mysql_select_db($database_LCA, $LCA);

$query_Icedancer = "SELECT * FROM animals WHERE animals.ARI=123076";

$Icedancer = mysql_query($query_Icedancer, $LCA) or die(mysql_error());

$row_Icedancer = mysql_fetch_assoc($Icedancer);

$totalRows_Icedancer = mysql_num_rows($Icedancer);

$sign="$";

?>

 

Man, this is killin' me! Thanks for your help.

 

 

 

 

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.