Jump to content

Recommended Posts

Hi All i have a function

 

function showQuoteList()
{
	include 'includes/dbconn.php';

	$res = $pdo->query("WITH priceinfo as (
        SELECT qi.quote_id, SUM(discounted_price * quantity * chargable_units) as price
            from quote_items qi
            group by quote_id
                 
        )
        
        
        SELECT client.company_name as companyName
								, job.name as jobName
								, quote.id as quoteId
								, quote.name as quoteName
								, version
								, currency
								, job.internal_ref
								, kit_delivery
								, kit_return
								, quote_status_id
								, total_value 
								, quote_status.status
								, quote.date_created
								, price
								, client.id as clientId
								,client.company_name as clientName
                           from quote
                           inner join client on quote.client_id = client.id
                           inner join job on quote.job_id = job.id
                           inner join quote_status on quote.quote_status_id = quote_status.id
                           inner join priceinfo on quote.id = priceinfo.quote_id
                           order by companyName, version desc
            ");
	$data = $res->fetchAll(PDO::FETCH_ASSOC);
	if (!$data) {
		$out = "<div class='alert alert-danger'>There are no quotes to show - create one by clicking <a href='clients'>here</a></div>";
	} else {


		$results = [];
		$out = '';
		foreach ($data as $u) {
			$results[$u['companyName']][$u['jobName']][$u['quoteId']] = array_slice($u, 2);
		}

		foreach ($results as $client => $jobs) {


			$out .= "<div class='card mb-4'>";
			foreach ($jobs as $j => $items) {
				foreach ($items as $i) {
					$out .= "<div class='card-header'><a href='jobs?clientId=$i[clientId]&cN=$i[clientName]'><strong>$client</strong></a></div>";
				}
			}
              
              ..........

 

the issue that i have is that when i put the line;

 

$out .= "<div class='card-header'><a href='jobs?clientId=$i[clientId]&cN=$i[clientName]'><strong>$client</strong></a></div>";

in its current location - it is displayed multiple times as there are multiple data sets in the $items and $i.

When i move the line up inside the $jobs as $j loop, which is where it should be to display the correct information - i dont have access to the variables that i need from $i.

 

how do i get access to the variables in $i keeping that line where it should be?

 

If this is not enogh information please let me know and i will provide more context.

Link to comment
https://forums.phpfreaks.com/topic/317644-getting-access-to-data-deeper-in-array/
Share on other sites

Sounds like the preprocessing you're doing on your data, namely the $results array, doesn't suit your needs.

Take a sample of your data and write it directly into your code, putting it into an array format that you can work with. Toy around with it until you get something that works. Then pull that stuff out and write code to generate the array from $data.

Advice: it's totally okay to have something more complicated than a plain 3D array.

array(
    some info here,
    sub data => array(
        maybe more info here,
        sub data => array(
            stuff
        )
    )
)

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.