Solved

php mysql get another table from ids in an array

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

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 108

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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…
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.

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now