Adamhumbug Posted January 21 Share Posted January 21 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. Quote Link to comment https://forums.phpfreaks.com/topic/317644-getting-access-to-data-deeper-in-array/ Share on other sites More sharing options...
requinix Posted January 21 Share Posted January 21 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 ) ) ) Quote Link to comment https://forums.phpfreaks.com/topic/317644-getting-access-to-data-deeper-in-array/#findComment-1614279 Share on other sites More sharing options...
Andou Posted January 21 Share Posted January 21 I'll add that var_dump helps a lot when dealing with arrays. I always use <?php echo '<pre>' . var_dump($array); . '</pre>; so I can see what's going on with it. 1 Quote Link to comment https://forums.phpfreaks.com/topic/317644-getting-access-to-data-deeper-in-array/#findComment-1614287 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.