Jump to content

foreach loop problem, please help!


jamesxg1

Recommended Posts

Hiya!

 

I have an issue, here is my code.

 

<?php
class generateInvoice {

	private $invoiceID;

	public function __construct($invoiceID) {
		$this->_INID = mysql_real_escape_string($invoiceID);
	}

	public function __drawInvoice() {
		$get_invoice = "SELECT * FROM `invoices` WHERE `id` = '$this->_INID' LIMIT 1";
		$run_get_invoice = mysql_query($get_invoice);

		if($run_get_invoice) {
			if(mysql_num_rows($run_get_invoice) == 1) {
				while($invoice_m = mysql_fetch_assoc($run_get_invoice)) {

					if($invoice_m == 1) {
						$status = 'Awaiting Payment';
					} elseif($invoice_m == 2) {
						$status = 'Paid';
					}

					$items_mass = explode(',', $invoice_m['items']);

					foreach($items_mass as $item_key => $item_value) {
						$item_split = explode('-', $item_value);

						echo '<pre>' . print_r($item_split, true) . '</pre>';

						foreach($item_split as $item_key_final => $item_value_final) {
							$invoice .= '
								<tr class="item-row">
									<td class="item-name"><div class="delete-wpr">' . $item_value_final[1] . '</div></td>
									<td class="description">THIS IS THE DESCRIPTION</td>
									<td><span class="cost">$650.00</span></td>
									<td><span class="qty">1</span></td>
									<td><span class="price">$650.00</span></td>
								</tr>';
						}
					}
				}

				return $invoice;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
}
?>

 

This is what is displayed.

 

Array

(

    [0] => 1

    [1] => Test Product

    [2] => 6.99

    [3] => 2

)

 

Array

(

    [0] => 5

    [1] => Tester Product

    [2] => 600.99

    [3] => 1

)

 

THIS IS THE DESCRIPTION $650.00 1 $650.00

e

THIS IS THE DESCRIPTION $650.00 1 $650.00

.

THIS IS THE DESCRIPTION $650.00 1 $650.00

THIS IS THE DESCRIPTION $650.00 1 $650.00

THIS IS THE DESCRIPTION $650.00 1 $650.00

e

THIS IS THE DESCRIPTION $650.00 1 $650.00

0

THIS IS THE DESCRIPTION $650.00 1 $650.00

THIS IS THE DESCRIPTION $650.00 1 $650.00

 

I need it so that I can use each of the array's above and echo out each item (key) individually. I don't understand whats going wrong?

 

Many thanks,

 

James.

 

Link to comment
Share on other sites

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.