Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

php mysql get another table from ids in an array

Posted on 2014-02-10
4
Medium Priority
?
362 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 111

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 111

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

916 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