Solved

PHP Query, OUTPUT

Posted on 2011-03-17
5
268 Views
Last Modified: 2012-05-11
Hi Experts,

Ive got a query that returns results from a database but does not return all entries under the "last_spoken_to" field.. which is in the notes table..

the current query i have is as follows:

$sql = "select * from customer left join notes on customer.customer_name = notes.customer_name WHERE customer.customer_name = '" . $val . "'";

I have tried the following:

$sql = "select * from customer left join notes on customer.customer_name = notes.customer_name AND customer.customer_name = last_spoke_to.customer_name WHERE customer.customer_name = '" . $val . "'";

but that does not work, it returns an error, What i have got is attached in the picture, And i need it to produce the same output as the notes category.

Many thanks

AS you can see from the picture Notes repeats but last spoke to does not how would i get it to repeat like the notes? as i stated ive tried the above query but that did not work.


 
picture5.jpg
0
Comment
Question by:NeoAshura
  • 2
  • 2
5 Comments
 
LVL 6

Assisted Solution

by:brb6708
brb6708 earned 250 total points
ID: 35155553
so far i can see is "last_spoke_to" a field in one of the tables "customer" or "notes".

The way you use it is wrong because "last_spoke_to.customer_name" combines two field names which is not correct.

So to answer your question it is necessary to get information abot the tables and fiellds in the database description.
0
 
LVL 16

Accepted Solution

by:
Chris Harte earned 250 total points
ID: 35155563
You say last_spoke_to is a field rather than a table, so should the second query not be

$sql = "
SELECT *
FROM customer
    LEFT JOIN notes
        ON customer.customer_name = notes.customer_name
        AND customer.customer_name = notes.last_spoke_to
WHERE customer.customer_name = '" . $val . "'";
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35155582
thanks for the feedback now my tables returns nothing they are blank...

Both notes is a table and contains "notes" and "last_spoke_to"

where customer is another table and customer_name is a field in that table which also exsits in the notes table as a referance for the notes and last spoke to. does that make sense?
0
 
LVL 6

Expert Comment

by:brb6708
ID: 35155587
@MunterMan:

that was my idea as well; but does it make sense selecting all customers who have talked to themselves?????

That's why I said that knowledge about the tables and the fields within those tables is necessary to answer NeoAshura's question.
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35155711
ok guys ive solved it but i appricate your input so points will be awrded equally. Ive outputed what i needed using the following:

$sql = "
SELECT *
FROM customer
    LEFT JOIN notes
        ON customer.customer_name = notes.customer_name
WHERE customer.customer_name = '" . $val . "'";

It is a notes page based on each customer, These notes needed to be logged.. it now looks as follows which is what i needed.
picture6.jpg
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

813 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

10 Experts available now in Live!

Get 1:1 Help Now