array empty


Posted on 16th Feb 2014 07:03 pm by admin

Hiya peeps,

Ok here is the codes.

order.php

Code:
<?php

if(!isset($_POST) OR empty($_POST)) {

echo '<h1 align="center">There was an error with your order!</h1><h2 align="center"><a href="index.php">Start again</a></h2>';
} else {

$tesco = new Tesco();

foreach($_POST as $key => $value) {

$tesco->getPrice($value, $key);


}


echo '<h1><u>You ordered:</u></h1>';

echo '<h2>'.$cnt[$row['id']].' x '.$row['name'].'</h2>';


echo '<h1><u>Results</u></h1>';
echo '<h2>Cheapest at: ' . $store . '</h2>';
echo '<h2>Amount: &pound;'.$total.'</h2>';

if($total > 50) {

echo '<a href="" onclick="" class="buttonn">Deliver it!</a>';

} elseif ($total < 50) {

echo '<a href="" onclick="" class="buttonn">Deliver it for &pound;9.99!</a>';

}
}

?>

tesco.php

Code: <?php
class Tesco {

private $quantity;
private $productid;

function getPrice($quantity, $productid, $storeid = '1') {

$this->quantity = mysql_real_escape_string(trim(addslashes(strip_tags(is_numeric($quantity)))));
$this->productid = mysql_real_escape_string(trim(addslashes(strip_tags(is_numeric($productid)))));
$this->storeid = mysql_real_escape_string(trim(addslashes(strip_tags(is_numeric($storeid)))));


$this->query = "SELECT * FROM `products` WHERE id = '$this->productid' AND store = '$this->storeid'";
$this->result = mysql_query($this->query) or trigger_error('Query failed: ' . mysql_error(), E_USER_ERROR);

while($this->price = mysql_fetch_object($this->result)):

if($this->quantity > 1):

$this->total[] = $this->price->price*$this->quantity;

elseif ($this->quantity = 1):

$this->total[] = $this->price->price;

endif;


endwhile;

print_r($this->total);

}




}
?>

As you can see in the tesco.php file i have a print_r() this is what is being returned..

Array ( => ) Array ( => [1] => )

(i have inputed two product id's).

Many thanks

No comments posted yet

Your Answer:

Login to answer
113 Like 24 Dislike
Previous forums Next forums
Other forums

Help With Showing Users On the Index Page
Ive got this code which works just how i want it to.

Code: <?
$timenow=time();

Strange array issue, never happened before.
mysql_fetch_array returns 1 array per call. Generally that's why it is inserted into a while statem

Upload, SSL and more php help
I recently just installed a ssl cert and do i use https for the whole site or just for the checkout.

Easy administration on MySQL databases
My website is database driven and I am very tired of manually making queries to my tables in order t

How to show a complete textarea ??
I enter Client Case Notes notes in a textarea field on a PHP form. The field is 5 rows deep and 70 c

PHP header help!
Hi all I am trying to get this php page to refresh every 5 seconds on my phone which is an aastra 48

PHP5/Zend 2.0 - Resources
PHP5 Snapshots
http://snaps.php.net/

ZEND 2.0 Feature Overview and Design (PDF File

php mysql script to find record
Hi,

Currently I have a simple table with 4 columns. A, B, C, D

If I want to find all

Problem with creating FI documents
Hi, Experts!

when i create Fi doc. with standart transaction, i ve been had such problem

Table sorting
Hi,

I'm trying to modify the following in order to make the output table sorted alphabeticall

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash