Solved

php mysql get another table from ids in an array

Posted on 2014-02-10
4
360 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

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
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

635 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