Page 1 of 1

A bit new (A question)

Posted: Tue Nov 02, 2004 9:18 am
by AMHE
patrikG | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Hi All,

I'm a bit new to php and I'm working on random recordsets for a shopping site. My random script works great and pulls info from my datatbases perfectly BUT i'm getting some weird stuff with my prices. For some reason my prices have extra 0's added to the end.

This is my code...

Code: Select all

<?php require_once('Connections/petgiftshop.php'); ?>
<?php
mysql_select_db($database_petgiftshop, $petgiftshop);
$query_Recordset1 = "SELECT * FROM products";
$Recordset1 = mysql_query($query_Recordset1, $petgiftshop) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="styles.css" rel="stylesheet" type="text/css">
</head>

<body>

<?php $query = "SELECT * products";
$result = MYSQL_QUERY($query);
$randval = rand(0, mysql_num_rows($Recordset1) - 1);

$title = mysql_result($Recordset1, $randval, 27);
$image = mysql_result($Recordset1, $randval, 19);
$price2 = mysql_result($Recordset1, $randval, 13);
$price = mysql_result($Recordset1, $randval, 12);
$description = mysql_result($Recordset1, $randval, 30);
$id = mysql_result($Recordset1, $randval, 0);
echo strtolower($row_Recordset1['$image']);
print("<p class='headerbold'>$title</p>
		<img src='http://www.petgiftshop.com/images/products/$image.jpg' width='100' height='100'>
		<p class='copy'>$description</p>
		
		<span class='copyboldheader'>Product Details</span>
		<hr>
		<span class='copybold'>Unit Price : <s>&#36;$price2</s> <span class='copyboldred'>&#36;$price</span> <br>
		<a href='http://www.petgiftshop.com/index.php?p=product&id=$id' target='_blank' class='copy'>Te ll me more! </a>"
		
		);
 ?>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
And this is what I see....


ItaltrendFaux Leopard Coat for Dogs

<IMAGE>

The reverse side of this coat is Gold Discodot. We have just developed a new line of faux fur coats for dogs. They were designed in Italy where we have our origins, but are manufactured in Las Vegas inhighly specialized labs under our constant control. The materials have been accurately selected among the very best and the look is extremely close to real furs. The reverse material is the latest in design of high fashion for ladies. Our garments are reversible and extremely elegant on both sides. Each garment is accurately hand sewn in all detailsfor a quality look.
Product Details
------------------------------------------------------------------------
Unit Price : $0.00000 $88.00000 <-----Any idea why these are coming from?
Te ll me more!

Any and all help is greatly appreciated. Thank You.

patrikG | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Tue Nov 02, 2004 12:10 pm
by lostboy
whats the field type in the db?

Posted: Tue Nov 02, 2004 12:45 pm
by AMHE
I can't change the DB. Its conmnected to a third party program and their code is kept under wraps.

I am currenylu able to use the round() command or (float) to remove all of the zeros, unfortunately it makes the prices look foolish.

a price of 47.50 becomes 47.5

by using $price2=round($price2, 2)

Posted: Tue Nov 02, 2004 12:46 pm
by lostboy
use number_format()

Posted: Tue Nov 02, 2004 12:47 pm
by AMHE
I actually was playing with that earlier as well.

What would you suggest because it seems to round off the digits?

Posted: Tue Nov 02, 2004 12:49 pm
by lostboy
number_format ( float number [, int decimals [, string dec_point, string thousands_sep]])

so use

number_format($number, 2, '.', '');

Posted: Tue Nov 02, 2004 1:58 pm
by AMHE
Ya, I was playing that earlier..worked great thanks

$price2 = number_format($price2, 2, '.', '');