Forum Moderators: coopster

Message Too Old, No Replies

number format function not working

Can't output price from database.

         

erdy

11:33 pm on Mar 22, 2008 (gmt 0)

10+ Year Member



Hi,

I am very new to PHP and have set up a table in a MySQL database. The database is called 'newstar' and the table is called 'products' this has a column called

Price_Prod
. The column type is Decimal(9,2).
Typical values in this column are:

3.49
3.99
3.99
3.49


etc,etc.

I have tried to take these values out of the database with the following script:


<?php

$cntx=mysqli_connect("localhost","root","password","newstar")
or die ("New star Access denied");

$query="SELECT * FROM PRODUCTS WHERE Prod_Price = 3.49";

$result = mysqli_query($cntx,$query)
or die ("Query Not Executed!");

while($length = mysqli_fetch_assoc($result))

{

extract ($length);

$f_price = number_format($Prod_Price,2);

echo $Prod_Name, " ";

echo $f_price, "<br/>";

}

?>

The result I get for this is:


Chicken Curry 0.00
Chicken Fu Yung 0.00
Chicken Chop Suey 0.00
Chicken Chow Main 0.00
Chicken Pineapple 0.00
Chicken Satay 0.00

Its like theirs no value in the $f_price.

Please help if you can.

Regards

erdy.

Habtom

3:47 am on Mar 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



...has a column called Price_Prod.

$f_price = number_format($Prod_Price,2);

Change $Prod_Price to $Price_Prod.

erdy

9:31 pm on Mar 23, 2008 (gmt 0)

10+ Year Member



Hi Habtom,

thanks for the reply. Sorry the mistake was only in the post I sent to the forum not in the actual Database.
I do have the values in the database column as 3.49 etc.
Should I have them as 349 instead?
Bearing in mind that the column type is decimal(9,2).

What would you use as a column type for a list of product prices?

Thanks

Erdy

jatar_k

3:07 pm on Mar 24, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could just as easily use a string