...

View Full Version : How to hide entry when value is 0



Bar2aYunie
06-22-2010, 09:16 PM
Hiya,

I have a couple of products in my database and they have different prices depending on the amount. As there is a small calculation (math) that I have to do with these prices, they must be set as 'NUMERIC float' in the database.

However, some products have 22 prices (max)whereas others have less. The float field cannot be left empty, so it fills up with a 0.

Now my question... How can I make sure that when there's a '0', that field is ignored/not shown?

thx!

met
06-22-2010, 09:21 PM
without seeing any code we can't provide anything accurate



if($r['price']>0) {
// show whatever...anything with a price of 0 will not be processed
}


SQL query can be adjusted

WHERE value > 0

etc.

Bar2aYunie
06-22-2010, 09:31 PM
Ah okay, sorry. Here's a part of my code (at select query):



<?php
// previous code
$finalQuery=mysql_query("SELECT * FROM `Folders` WHERE `size`='{$size}' AND `color`='{$color}';");

while($item=mysql_fetch_array($finalQuery)){
$base_m=5;
$item['price1'] = round ((($item['price1']+5) *1.85),0);
$item['price01'] = $base_m*(ceil(($item['price1'])/$base_m));
// these 2 rows are repeated 22 times with price2, price02, price3, price03 and so on

if ($column==1) {echo "<tr>";}
?>

<td width="50%" align="center"><h4><?php echo "{$item['amount1']}<br /> {$item['amount2']}<br /> {$item['amount3']}<br /> {$item['amount4']}<br /> {$item['amount5']}<br /> {$item['amount6']}<br /> {$item['amount7']}<br /> {$item['amount8']}<br /> {$item['amount9']}<br /> {$item['amount10']}<br /> {$item['amount11']}<br /> {$item['amount12']}<br /> {$item['amount13']}<br /> {$item['amount14']}<br /> {$item['amount15']}<br /> {$item['amount16']}<br /> {$item['amount17']}<br /> {$item['amount18']}<br /> {$item['amount19']}<br /> {$item['amount20']}<br /> {$item['amount21']}<br /> {$item['amount22']}<br />" ?></h4></td>
<td width="50%" align="center"><h4><?php echo "{$item['price01']}<br /> {$item['price02']}<br />{$item['price03']}<br />{$item['price04']}<br />{$item['price05']}<br />{$item['price06']}<br />{$item['price07']}<br />{$item['price08']}<br />{$item['price09']}<br />{$item['price010']}<br />{$item['price011']}<br />{$item['price012']}<br />{$item['price013']}<br />{$item['price014']}<br />{$item['price015']}<br />{$item['price016']}<br />{$item['price017']}<br />{$item['price018']}<br />{$item['price019']}<br />{$item['price020']}<br />{$item['price021']}<br />{$item['price022']}<br />" ?></h4></td>
// rest of code


As there are 22 prices, I don't think I can add them all into the select where query....right?

I'm not too sure how to add in the other part you suggested. Does this part of the code helps?

Keleth
06-22-2010, 09:36 PM
If I understand you correctly, that the db may have price values of 0 and you want to ignore those, you can simply add what he mentioned onto the query:


$finalQuery=mysql_query("SELECT * FROM `Folders` WHERE `size`='{$size}' AND `color`='{$color}' AND `price` > 0;");

Thats the best method IMO... you could also:


while($item=mysql_fetch_array($finalQuery)){ if ($item['price'] > 0) {

Bar2aYunie
06-22-2010, 10:18 PM
Yes, you understood me correctly. However, I knew about the method to add it in the select query... But since I have 22 prices, I'd have to add that 22 times, same for adding it into the while. Right?

If so, I think it's best to add it into the while, to make it better to read. Don't you think? You have the '{' two times. I also have one of my own. Do I need to add another } after the whole while?

Which option would you suggest? (knowing I'd have to add the price1, price2 and so on 22 times) And, won't this mess up with my calculation? Where all of the prices (price1, price2, price 3 and so on) are changed into prices0 (price01, price02, price03 and so on).

Keleth
06-22-2010, 10:29 PM
Maybe I didn't understand you correctly...

You're saying for a single item you might have 22 prices? Or that there are 22 items? I'm not following why you'd need to do 22 queries...

If your only concern is summation, it doesn't matter as adding 0 doesn't add anything obviously... and what do you mean by "prices0"? There is some detail I'm not following.

Can you show us how your DB is setup? With real/fake data if possible. I think that would clear it up.

Bar2aYunie
06-22-2010, 10:56 PM
Yeah sure, here's the amount and prices part:


`amount1` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '250',
`amount2` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '1000',
`amount3` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '2500',
`amount4` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '5000',
`amount5` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '10.000',
`amount6` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '15.000',
`amount7` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '20.000',
`amount8` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '25.000',
`amount9` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '30.000',
`amount10` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '35.000',
`amount11` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '40.000',
`amount12` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '45.000',
`amount13` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '50.000',
`amount14` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '55.000',
`amount15` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '60.000',
`amount16` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '65.000',
`amount17` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '70.000',
`amount18` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '75.000',
`amount19` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '80.000',
`amount20` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '85.000',
`amount21` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '90.000',
`amount22` varchar(20) COLLATE utf8_bin NOT NULL DEFAULT '95.000',
`price1` float NOT NULL,
`price2` float NOT NULL,
`price3` float NOT NULL,
`price4` float NOT NULL,
`price5` float NOT NULL,
`price6` float NOT NULL,
`price7` float NOT NULL,
`price8` float NOT NULL,
`price9` float NOT NULL,
`price10` float NOT NULL,
`price11` float NOT NULL,
`price12` float NOT NULL,
`price13` float NOT NULL,
`price14` float NOT NULL,
`price15` float NOT NULL,
`price16` float NOT NULL,
`price17` float NOT NULL,
`price18` float NOT NULL,
`price19` float NOT NULL,
`price20` float NOT NULL,
`price21` float NOT NULL,
`price22` float NOT NULL,


So for amount 1 (which is by default 250) there's a certain price and then we've got 21 more amounts and thus also 21 more prices...

Here's data for one of my products (for those rows):



VALUES('250', '1000', '2500', '5000', '10.000', '15.000', '20.000', '25.000', '30.000', '35.000', '40.000', '45.000', '50.000', '55.000', '60.000', '65.000', '70.000', '75.000', '80.000', '85.000', '90.000', '95.000', '100.000', '', '', 29.37, 37.08, 46.02, 48.89, 79.13, 103.03, 122.47, 164.16, 183.6, 213.49, 232.94, 274.63, 294.07, 323.96, 343.41, 385.1, 404.54, 434.43, 453.88, 483.77, 515.01, 544.9, 564.34);


I hope this clears it out why I need more prices? If not ask and I'll try to explain another way.

Edit: as for price01, price02, price03 and so on... There's an administration cost to the basic price of 5 dollar (basic price is in database) and a multiplyer of 1,85. So therefore, I needed a math function to get the right price. So I wouldn't have to calculate them myself when adding them into the db.

Keleth
06-22-2010, 11:00 PM
So... you have 47 columns... I think that's the first problem right there. I can't be sure given I don't know all your facts, but I'm fairly certain the database could be setup better then that...

Regardless, I am totally confused on what you're trying to achieve now. If the issue is summing a 0 in, why should that matter? 0 is the summation identity, adding it won't do anything.

Bar2aYunie
06-22-2010, 11:12 PM
To be honest, I've got 64 columns.... Since there's a lot more data than just the prices or the amounts. But most of the columns are for the amounts and the prices, yaan. It is possible yeah that this isn't the best way to set it up....but as I've got 475 sub-products and 18 main products and all of this data to get into a db, this was the easiest way I could think of.... and it all works...

Now, lets say that one of my products has 5 different amounts available and thus 5 different prices. The products are folders (like small magazines) and ppl can order them. The prices vary depending on the amount they want.

So let's list the amounts and prices:
250 folders = 29.37 dollar
1000 folders = 37.08 dollar
2500 folders = 46.02 dollar
5000 folders = 48.89 dollar
10.000 folders = 79.13 dollar

Now, after adding the administration cost of 5 dollar and adding the multiplyer of 1,85 the new prices become:

250 folders = (29.37 + 5) * 1,85 = 63,58 dollar
and so on for the other prices.

Lastly, I stated that every price must be rounded by 5, always up. So 63,58 will become 65. That is the calculation I made.

As in this example, there are 5 prices, from 5 different columns called, I need to add in the calculation 5 times.

However... For some products, there aren't just 5 prices, but 22! Now for those products, I need to recall 22 columns. But, for the products with just 5 prices (and amounts) I only want the script to show 5 prices, not all of them with an empty value.

Since the price columns are set to float, an empty column cannot stay empty and it is automatically filled with 0. However, if there's no amounts after the 5 in our example, there cannot be any prices, especially not if the price is 0 (due to the db setup). So I want those values ignored.

I hope I made myself a bit more clear and you understand what I'm trying to achieve. Sorry if I'm not good in explaining... (it's a bit too obvious to me probably, haha)

Keleth
06-22-2010, 11:16 PM
Yah, if I get you this time, then its not a mySQL issue, its a PHP issue. Use the while example above (while (something) { if (prices != 0) { whatever } })

Bar2aYunie
06-22-2010, 11:22 PM
So it would be like this?


while($item=mysql_fetch_array($finalQuery)){
if (price1 != 0) {
$base_m=5;
$item['price1'] = round ((($item['price1']+5) *1.85),0);
$item['price01'] = $base_m*(ceil(($item['price1'])/$base_m));
// repeated 22 times
if ($column==1) {echo "<tr>";}
}
?>


And can I say: if (price1 != 0), (price2 != 0), (price3 != 0) and so on... ?
Or how do I add in the other prices?

This way, even if there's a calculation for a price where the value is 0, the whole calculation and price is ignored??

Keleth
06-22-2010, 11:31 PM
well, it'd be $item['price1'] != 0 but yah... there's no neat efficient way do it I can think of... except maybe an array with a foreach loop:


$priceList = array('price1', 'price2', ...) //all columns
foreach ($priceList as $indivPriceCol) {
if ($item[$indivPirceCol] != 0) {
// do your calculations here
}
}

Its still messy and I feel the best way in the end will be to figure out your DB and redo that... You could have a table for prices, a table for quantities, and do your initial calculations in the query itself.

Do the amounts every change? If they don't, it shouldn't be in the DB as columns of their own... it just confuses the issue, takes up space, and without them you might be able to clear up the queries.

Bar2aYunie
06-22-2010, 11:31 PM
So that way, could I do this:



$priceList = array('price1', 'price2', ...) //all columns
foreach ($priceList as $indivPriceCol) {
$item['indivPriceCol'] != 0 {
$item['indivPriceCol'] = round ((($item['indivPriceCol']+5) *1.85),0);
$item['indivPriceCol'] = $base_m*(ceil(($item['indivPriceCol2'])/$base_m));
} }


Or did I miss what you were trying to say?

Bar2aYunie
06-23-2010, 09:14 AM
When I use any of your options, there's no data at all.... If I add it into the select query, I get no results (empty page). But if I add it in the 'if', I see everything, though no prices (prices column is empty).

I also tried adding the indivPriceCol loop, but that also gives me an empty price column....

Can't I use something like this:


if not Len(CCGetParam("n_onb","")) > 0 then
Results_AR.code_on.visible=false
ELSE
Results_AR.code_on.visible=true
END IF

I found that on the internet, but I'm not sure how to use it... thx for helping me!

Keleth
06-23-2010, 03:25 PM
I have no idea what that code is supposed to do, or if its even PHP. I've never seen PHP syntax like that.

Did you use the code I wrote AFTER you responded to my last post? I accidentally submitted then had to edit it to fix it. Because if you're using the code you put, its not going to work.

Bar2aYunie
06-23-2010, 10:53 PM
Forget that other thing, I was only trying to help, haha. had no idea what it meant, lol.

Yeah... I tried this:



while($item=mysql_fetch_array($finalQuery)){
$priceList = array('price1', 'price2', 'price3'); // added ; to get rid of error
// tested only with the first three to see if it would work, does that make any difference?
foreach ($priceList as $indivPriceCol) {
if ($item[$indivPirceCol] != 0) {

$base_m=5;
$item['price1'] = round ((($item['price1']+5) *1.85),0); $item['price01'] = $base_m*(ceil(($item['price1'])/$base_m));
// repeated 22 times

}}
}


But I get no price column.....

Keleth
06-24-2010, 12:42 AM
If thats a copy/paste, you misspelled price in "$item[$indivPirceCol]", or at least had an inconsistency in var names.

Bar2aYunie
06-24-2010, 06:40 AM
Lol, it was a direct copy....and it was late, haha.

Though, the result is the same... :S

Keleth
06-24-2010, 06:48 AM
Have you tried printing $item to confirm it contains the data you want?

Bar2aYunie
06-24-2010, 07:07 AM
No, how do I do that?

edit: gotta go now (work), be back later. thx for helping!

xGIHavoc
06-24-2010, 08:07 AM
Save us hah.
echo $item['price1']; within the loop and check if you are getting the appropriate output.

Keleth
06-24-2010, 02:54 PM
I was thinking


print_r($item);

to check the whole thing, but yah, same idea as what Havoc said.

Bar2aYunie
06-24-2010, 09:51 PM
Okay, well I figured out that if I change the value to 'price1' instead of 'price01', the original value is shown (no calculation and when the value is 0, the value 0 is shown). If I add the echo within the loop, it shows the original value (no calculation) also, if the value is 0, the value 0 is shown.

So both of the effects I'm trying to add aren't working: the calculation and the fact that it shouldn't hide any values of 0....

edit:

adding your print code shows all of the original data from the db, no calculation and no hidden 0 values...

Keleth
06-24-2010, 10:02 PM
What do you mean?

I'm confused now... you do the calculation at the bottom of the loop, why would it show you the calculated price initially? Where are you echoing the result? And if you're checking if a variable != 0, there's absolutely no reason a 0 value should sneak through. I strongly suspect there is something here I didn't understand or a disconnect between what you're trying to do and the advice I gave you. My apologies if that's the case. Lemme look the thread over and see... cuz I'm really confused now.

EDIT: price1 isn't changing at all? And where is price01? I don't see it in the last code you provided. Can you copy/paste the relevant section again? I cannot see why price1 shouldn't change, given you have it hard coded into the forloop.

Bar2aYunie
06-24-2010, 10:21 PM
No I mean it doesn't show the calculated price. It shows the original price (what's in the db, before calculation) I echoed it after the while, after the array and after the foreach (doesn't work elsewhere). Your print code also works after the whole loop.

Lemme say what it's supposed to be doing before giving the code.
- select query -> gathers the desired data with the where's
- while
- array -> all prices are in the array
- foreach -> give array a new name
- if -> set foreach to != 0 to get rid of 0 values (name is indivPriceCol)
- calculation -> all prices are still called upon individually, then the math function is added and the outcome is given in price + 0 + pricenumber (so price1 is changed to price01, price2 is changed to price02 and so on)
- show data in table.

Here's the code as it is now. I think it has something to do with the fact that the hidden 0 function is referring to 'indivPriceCol', while the math function refers to the individual prices and so does the table to output the data. Should I change the array from price1 to price01 to get that data? Maybe we must add the hide 0 function beneath the calculation? (just some quick thoughts)



<?php
$finalQuery=mysql_query("SELECT * FROM `Folders` WHERE `size`='{$size}' AND `color`='{$color}';");

while($item=mysql_fetch_array($finalQuery)){
$priceList = array('price1', 'price2', 'price3', 'price4', 'price5', 'price6', 'price7', 'price8', 'price9', 'price10', 'price11', 'price12', 'price13', 'price14', 'price15', 'price16', 'price17', 'price18', 'price19', 'price20', 'price21', 'price22');
foreach ($priceList as $indivPriceCol) {
if ($item[$indivPriceCol] != 0) {

$base_m=5;
$item['price1'] = round ((($item['price1']+5) *1.85),0); $item['price01'] = $base_m*(ceil(($item['price1'])/$base_m));
$item['price2'] = round ((($item['price2']+5) *1.85),0); $item['price02'] = $base_m*(ceil(($item['price2'])/$base_m));
$item['price3'] = round ((($item['price3']+5) *1.85),0); $item['price03'] = $base_m*(ceil(($item['price3'])/$base_m));
$item['price4'] = round ((($item['price4']+5) *1.85),0); $item['price04'] = $base_m*(ceil(($item['price4'])/$base_m));
$item['price5'] = round ((($item['price5']+5) *1.85),0); $item['price05'] = $base_m*(ceil(($item['price5'])/$base_m));
$item['price6'] = round ((($item['price6']+5) *1.85),0); $item['price06'] = $base_m*(ceil(($item['price6'])/$base_m));
$item['price7'] = round ((($item['price7']+5) *1.85),0); $item['price07'] = $base_m*(ceil(($item['price7'])/$base_m));
$item['price8'] = round ((($item['price8']+5) *1.85),0); $item['price08'] = $base_m*(ceil(($item['price8'])/$base_m));
$item['price9'] = round ((($item['price9']+5) *1.85),0); $item['price09'] = $base_m*(ceil(($item['price9'])/$base_m));
$item['price10'] = round ((($item['price10']+5) *1.85),0); $item['price010'] = $base_m*(ceil(($item['price10'])/$base_m));
$item['price11'] = round ((($item['price11']+5) *1.85),0); $item['price011'] = $base_m*(ceil(($item['price11'])/$base_m));
$item['price12'] = round ((($item['price12']+5) *1.85),0); $item['price012'] = $base_m*(ceil(($item['price12'])/$base_m));
$item['price13'] = round ((($item['price13']+5) *1.85),0); $item['price013'] = $base_m*(ceil(($item['price13'])/$base_m));
$item['price14'] = round ((($item['price14']+5) *1.85),0); $item['price014'] = $base_m*(ceil(($item['price14'])/$base_m));
$item['price15'] = round ((($item['price15']+5) *1.85),0); $item['price015'] = $base_m*(ceil(($item['price15'])/$base_m));
$item['price16'] = round ((($item['price16']+5) *1.85),0); $item['price016'] = $base_m*(ceil(($item['price16'])/$base_m));
$item['price17'] = round ((($item['price17']+5) *1.85),0); $item['price017'] = $base_m*(ceil(($item['price17'])/$base_m));
$item['price18'] = round ((($item['price18']+5) *1.85),0); $item['price018'] = $base_m*(ceil(($item['price18'])/$base_m));
$item['price19'] = round ((($item['price19']+5) *1.85),0); $item['price019'] = $base_m*(ceil(($item['price19'])/$base_m));
$item['price20'] = round ((($item['price20']+5) *1.85),0); $item['price020'] = $base_m*(ceil(($item['price20'])/$base_m));
$item['price21'] = round ((($item['price21']+5) *1.85),0); $item['price021'] = $base_m*(ceil(($item['price21'])/$base_m));
$item['price22'] = round ((($item['price22']+5) *1.85),0); $item['price022'] = $base_m*(ceil(($item['price22'])/$base_m));
}}

if ($column==1) {echo "<tr>";}
?>
<td width="50%" align="center"><?php echo "<img src='{$item['thumb_size']}' alt='{$item['thumb_size']}' border='2' style='border-color: #6E1244;' />" ?></td>
<td width="50%" align="left">Folders <br /><?php echo "{$item['size']}<br />" ?>Total Size: <?php echo "{$item['totalsize']}<br />" ?>Final Size: <?php echo "{$item['finalsize']}<br />{$item['color']}<br />{$item['material']}<br />{$item['Info']}" ?></td>
</tr><tr>
<td width="50%" align="center"><h1>Amount</h1></td>
<td width="50%" align="center"><h1>Prices</h1></td>
</tr><tr>
<td width="50%" align="center"><h4><?php echo "{$item['amount1']}<br /> {$item['amount2']}<br /> {$item['amount3']}<br /> {$item['amount4']}<br /> {$item['amount5']}<br /> {$item['amount6']}<br /> {$item['amount7']}<br /> {$item['amount8']}<br /> {$item['amount9']}<br /> {$item['amount10']}<br /> {$item['amount11']}<br /> {$item['amount12']}<br /> {$item['amount13']}<br /> {$item['amount14']}<br /> {$item['amount15']}<br /> {$item['amount16']}<br /> {$item['amount17']}<br /> {$item['amount18']}<br /> {$item['amount19']}<br /> {$item['amount20']}<br /> {$item['amount21']}<br /> {$item['amount22']}<br />" ?></h4></td>
<td width="50%" align="center"><h4><?php echo "{$item['price01']}<br /> {$item['price02']}<br />{$item['price03']}<br />{$item['price04']}<br />{$item['price05']}<br />{$item['price06']}<br />{$item['price07']}<br />{$item['price08']}<br />{$item['price09']}<br />{$item['price010']}<br />{$item['price011']}<br />{$item['price012']}<br />{$item['price013']}<br />{$item['price014']}<br />{$item['price015']}<br />{$item['price016']}<br />{$item['price017']}<br />{$item['price018']}<br />{$item['price019']}<br />{$item['price020']}<br />{$item['price021']}<br />{$item['price022']}<br />" ?></h4></td>

Keleth
06-24-2010, 10:33 PM
Uh... pretty obvious... you're looking through all the prices then calculating them anyway... the if is not working because if any of them are non-zero you calculate them all... You should just replace 'price1' etc with $indivPriceCol.

Bar2aYunie
06-24-2010, 10:36 PM
and how should I recall the prices in the table? one time as indivPriceCol? Or still 22 times? (I thought something like that would be messing up, just was unsure how exactly to fix it)

Keleth
06-24-2010, 10:40 PM
You only need to do one calculation per forloop iteration... just replace 'price1' etc with $indivPriceCol

Bar2aYunie
06-24-2010, 10:50 PM
Okay. My code is now:



<?php
$finalQuery=mysql_query("SELECT * FROM `Folders` WHERE `size`='{$size}' AND `color`='{$color}';");

while($item=mysql_fetch_array($finalQuery)){
$priceList = array('price1', 'price2', 'price3', 'price4', 'price5', 'price6', 'price7', 'price8', 'price9', 'price10', 'price11', 'price12', 'price13', 'price14', 'price15', 'price16', 'price17', 'price18', 'price19', 'price20', 'price21', 'price22');
foreach ($priceList as $indivPriceCol) {
if ($item[$indivPriceCol] != 0) {

$base_m=5;
$item['indivPriceCol'] = round ((($item['indivPriceCol']+5) *1.85),0); $item['indivPriceCol2'] = $base_m*(ceil(($item['indivPriceCol'])/$base_m));

}}
if ($column==1) {echo "<tr>";}
?>
<td width="50%" align="center"><?php echo "<img src='{$item['thumb_size]}' alt='{$item['thumb_size]}' border='2' style='border-color: #6E1244;' />" ?></td>
<td width="50%" align="left">Folders <br /><?php echo "{$item['size']}<br />" ?>Total Size: <?php echo "{$item['totalsize']}<br />" ?>Final Size: <?php echo "{$item['finalsize']}<br />{$item['color']}<br />{$item['material']}<br />{$item['Info']}" ?></td>
</tr><tr>
<td width="50%" align="center"><h1>Amount</h1></td>
<td width="50%" align="center"><h1>Prices</h1></td>
</tr><tr>
<td width="50%" align="center"><h4><?php echo "{$item['amount1']}<br /> {$item['amount2']}<br /> {$item['amount3']}<br /> {$item['amount4']}<br /> {$item['amount5']}<br /> {$item['amount6']}<br /> {$item['amount7']}<br /> {$item['amount8']}<br /> {$item['amount9']}<br /> {$item['amount10']}<br /> {$item['amount11']}<br /> {$item['amount12']}<br /> {$item['amount13']}<br /> {$item['amount14']}<br /> {$item['amount15']}<br /> {$item['amount16']}<br /> {$item['amount17']}<br /> {$item['amount18']}<br /> {$item['amount19']}<br /> {$item['amount20']}<br /> {$item['amount21']}<br /> {$item['amount22']}<br />" ?></h4></td>
<td width="50%" align="center"><h4><?php echo "{$item['indivPriceCol2']}<br /> " ?></h4></td>


For some reason, I only view price11.... no other prices. Apart from that. The calculation doesn't work... Since the values of every price seem to be added... I get huuuuuuuuuuuuge prices.

Edit: gotta go to bed, check back in like 7,5 hours... Thx again!

Keleth
06-24-2010, 11:04 PM
You don't wanna quote 'indivPriceCol'... its not a literal value... its a variable, so its $indivPriceCol.

Bar2aYunie
06-25-2010, 06:51 AM
It makes no difference. I tried unquoting all of them and I tried unquoting the indivPriceCol, but quoting the indivPriceCol2 (which is for the calculation)

Keleth
06-25-2010, 07:02 AM
You unquoted and put the $ for the variable and nothings happening? I can't see anything else wrong.

Not to mention, indivPriceCol2 is just gonna continually be rewritten, so you'll only get 1 value out of it.

Bar2aYunie
06-25-2010, 07:03 AM
Yeah and I need 22 different values.... so how do I get that?

Keleth
06-25-2010, 07:09 AM
By having a unique identifier? Have a number that counts up, and concatenate that onto something. Define a variable, probably as 1, before the loop, then inside the loop increment it after everything is done.

Bar2aYunie
06-25-2010, 07:12 AM
Hmm, I'll check but I don't think I know how to do that.....

(gotta go to work now, be back later today to try that)

Keleth
06-25-2010, 07:31 AM
Uh... I just told you how to do it... short of writing the code out for you...


$countVar = 1;
foreach ($priceList as $indivPriceCol) {
//Whatever code
$item['calcPrice'.$countVar] = //whatever
$countVar++;
}

Bar2aYunie
06-25-2010, 06:11 PM
So, if I understand correctly...

It's the countvar at the top of the code after the select query. then the array with all of the prices, then the foreach and the if. Then the calculation with the indivpricecol and then call the item calcprice. lastly the countvar before calling upon the indivpricecol to show the prices... Right?

I only do not know what to put after the countvar = //whatever. What you said. I am not asking to write the entire code for me, I'm just not sure with this bit of code haven't used it before....

Keleth
06-25-2010, 07:07 PM
Well... thats your calculation... I donno what to put there...

And no, the countvar is for that indivPriceCol2 you were talking about that was continually calculated without anything moving on... adding countVar will move it along the array.

Keleth
06-25-2010, 07:07 PM
Well... thats your calculation... I donno what to put there...

And no, the countvar is for that indivPriceCol2 you were talking about that was continually calculated without anything moving on... adding countVar will move it along the array.

Bar2aYunie
06-25-2010, 07:35 PM
So the calculation should come after: $item['calcPrice'.$countVar] = //whatever?

And the rest I said was correct? Then... should I refer to calcPrice to call upon the prices in the table? Or what does the calcPrice mean? I don't see it referring to anything...

edit:
The calculation should basically take the prices from the db and then add 5. Then multiply that number by 1,85. Lastly, I want it rounded up by 5. Meaning that an output of 47,56 after the calcuation should be rounded up to 50 and an output of 23,56 should be rounded up to 25. I changed the calculation a bit and now I've got it into one line, though with a lot of '('....

If it should come after the calcprice line I got this:


$item['calcPrice'.$countVar] = (5*(ceil(round ((($item[indivPriceCol]+5) *1.85),0))/5));



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum