Razvan2k3 Posted September 12, 2016 Share Posted September 12, 2016 (edited) Hello, I am glad I joined this forums, seems a good way to find out all about web-programming. I`m starting to check most of the topics. I am posting because I need an advice / solution to some project I am working on. Short info: It is in fact on a sub-page, where I wish to display some info from the MySQL database via PHP. Sub-Problem #1. I managed to display all other columns / rows but the last one is an actual "Operation = Subtraction" from the last 2. Since it is in an array, I do not know how to do that - to correlate one with another. Managed to make other info's on the site but when they were not in an array. $Profit = $Pret_sol - $Pret_achizitie (translation: profit = price asked to client - acquisition price) Sub-Problem #2. Also, as each ID (its an order number ID - can have multiple parts and prices - as shown in the picture - how can I only display totals value for an order ID (total $pret_sol / $pret_achizitie), so that it does not display each consecutive one? That would be all, please let me know your solutions or advice, I give you: 1. Website screen actual working. 2. Part of the code with the functions. Thank you very much! <div class="row"> <div class="col-sm-12"> <h4 class="page-title">Financiar rapoarte <font color="d3283c"> ></font> Toate facturile</h4> <div class="card-box table-responsive"> <table id="datatable-buttons" class="table table-hover m-0 table-bordered"> <thead> <tr> <th><font color="337ab7">Numar intrare</font></th> <th><font color="337ab7">Marca</font></th> <th><font color="337ab7">Model</font></th> <th><font color="337ab7">Data livrare</font></th> <th><font color="337ab7">Venit / Facturat</font></th> <th><font color="337ab7">Cheltuieli</font></th> <th><font color="5cb85c">Profit</font></th> </tr> </thead> <tbody> <?php $result = mysql_query("SELECT receptie.id, receptie.marca_tel, receptie.model, receptie.data_primire, articole_service.pret_sol, articole_service.pret_achizitie FROM receptie inner join articole_service on receptie.id = articole_service.id_receptie"); while ($row = mysql_fetch_array($result)) { ?> <tr> <td><?php echo $row['id']; ?></td> <td><?php echo $row['marca_tel']; ?></td> <td><?php echo $row['model']; ?></td> <td><?php echo $row['data_primire']; ?></td> <td><?php echo $row['pret_sol']; ?></td> <td><?php echo $row['pret_achizitie']; ?></td> <td>Profit=Pret_sol-Pret_achizitie</td> </tr> <?php } ?> </tbody> </table> </div> </div><!-- end col --> </div> <!-- end row --> Edited September 12, 2016 by Razvan2k3 Quote Link to comment https://forums.phpfreaks.com/topic/302155-help-for-a-php-select-script-for-my-website/ Share on other sites More sharing options...
ginerjm Posted September 12, 2016 Share Posted September 12, 2016 Some pretty old html and deprecated styling here. Have you thought about updating it? As for your question - how about showing us the real code and not all the presentation. Logic please. Quote Link to comment https://forums.phpfreaks.com/topic/302155-help-for-a-php-select-script-for-my-website/#findComment-1537400 Share on other sites More sharing options...
Solution Barand Posted September 12, 2016 Solution Share Posted September 12, 2016 Do the calculation in the query SELECT receptie.id , receptie.marca_tel , receptie.model , receptie.data_primire , articole_service.pret_sol , articole_service.pret_achizitie , articole_service.pret_sol - articole_service.pret_achizitie as profit -- add this FROM receptie inner join articole_service on receptie.id = articole_service.id_receptie then output $row['profit'] Quote Link to comment https://forums.phpfreaks.com/topic/302155-help-for-a-php-select-script-for-my-website/#findComment-1537404 Share on other sites More sharing options...
Razvan2k3 Posted September 12, 2016 Author Share Posted September 12, 2016 (edited) Do the calculation in the query SELECT receptie.id , receptie.marca_tel , receptie.model , receptie.data_primire , articole_service.pret_sol , articole_service.pret_achizitie , articole_service.pret_sol - articole_service.pret_achizitie as profit -- add this FROM receptie inner join articole_service on receptie.id = articole_service.id_receptie then output $row['profit'] Thank you very much - it works perfectly. And for my second problem - to display the totals for each id. As said: on an ID I have multiple articles prices / and profit for each article. I want to count total for an ID: edit - image removed Edited September 12, 2016 by Barand image removed - unsuitable content Quote Link to comment https://forums.phpfreaks.com/topic/302155-help-for-a-php-select-script-for-my-website/#findComment-1537437 Share on other sites More sharing options...
Barand Posted September 12, 2016 Share Posted September 12, 2016 As you process the results, accumulate the total. Check for a change of id and output the total on change. Quote Link to comment https://forums.phpfreaks.com/topic/302155-help-for-a-php-select-script-for-my-website/#findComment-1537443 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.