Solved

php mysql get another table from ids in an array

Posted on 2014-02-10
4
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 110

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 110

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

Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

752 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