Solved

php mysql get another table from ids in an array

Posted on 2014-02-10
4
357 Views
Last Modified: 2014-02-16
Hi
I have a program to print a delivery note, it reads a table tblDeliveryDate by input delivery_id, then it reads the matching delivery_id from tblOrdersReferral which has multiple entries for quantity and stock_group, I save these in an array quantity[] and stock_group[]
It takes referral_id[0] to access table tblReferralDetails to get the client_number in order to access table tblClient for the delivery name and address.
I had all this working, but as well as the quantity and stock_group I need the stock description from tblStockDescriptions
The keys to this table are in the array stock_group[] and I have become stuck trying to get them.
The code is attached.
I have tried following suggestions picked up by googling but I'm just getting more confused.
I want quantity [0,1,2,3] and stock_group [0,1,2,3] with stock_description[0,1,2,3] obtained from tblStockDescriptions with reference to the matching stock_group
failingcode.php
0
Comment
Question by:peter_lawrie
  • 2
  • 2
4 Comments
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39849957
The code is not really useful (we already know it does not work) but if we had some of the test data we might be able to show you how the relational nature of the RDBMS would work for you.

Please post the CREATE TABLE statements (including comments) and a few rows of the test data so we can load up the tables.  Then we should be able to show you the query and logic needed to get the right information together.  An example of how to run the CREATE TABLE and load the test data is given in this article.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
0
 

Accepted Solution

by:
peter_lawrie earned 0 total points
ID: 39851142
Hi ]I managed after much trial and error and struggling with an obtuse manual, to make it work - here is my coding

        //get OrdersReferral and StockDescriptions
        $get_tblOrdersReferral_sql = "SELECT delivery_id, stock_group, quantity, stock_description
                         FROM tblOrdersReferral INNER JOIN tblStockDescriptions
                        USING (stock_group)
                          WHERE delivery_id =  '$delivery_id'";
        $get_tblOrdersReferral_res = mysqli_query($mysqli, $get_tblOrdersReferral_sql)
                         or  die(mysqli_error($mysqli));

        if (mysqli_num_rows($get_tblOrdersReferral_res) > 0) {
            while ($ordstock_info = mysqli_fetch_array($get_tblOrdersReferral_res)) {
                $stock_description[] = stripslashes($ordstock_info['stock_description']);
                $stock_group[] = stripslashes($ordstock_info['stock_group']);
                $quantity[] = stripslashes($ordstock_info['quantity']);
           }
        }
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39851225
Glad you got it working.  Going forward you might want to learn about the SSCCE.  It's the best way that I've ever found to get help with any kind of software development challenge.
0
 

Author Closing Comment

by:peter_lawrie
ID: 39862477
got it to work myself
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP Installer 5 38
Using cfstoredproc to return query data 2 30
Custom Wordpress Loop 22 39
Combining Queries 7 28
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question