Solved

Display query results even if I can't match 2 columns from 2 different tables

Posted on 2010-09-07
2
261 Views
Last Modified: 2013-12-13
Here is my query

SELECT hlp_hed_key, hlp_chan_num, hlp_callsign, FullName FROM gn_stage.stg_stations, gn_config.cfg_headend_lineup WHERE hlp_callsign=Call_Sign AND hlp_hed_key='$h' ORDER BY hlp_chan_num + 0 ASC

Open in new window


I display the results of this query in my webpage.  The problem is that if hlp_callsign does not match a field in Call_Sign then the row doesn't display at all.  I would like to display all of the other data and perhaps show hlp_callsign in red indicating it is bad and needs edited.

Thanks for the help on this.
0
Comment
Question by:kevandju
2 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
ID: 33621739
SELECT hlp_hed_key, hlp_chan_num, hlp_callsign, FullName
FROM gn_config.cfg_headend_lineup left join gn_stage.stg_stations
 ON hlp_callsign=Call_Sign
WHERE hlp_hed_key='$h'
ORDER BY hlp_chan_num + 0 ASC


It would be a good idea to alias the table names... and to indicate where each column comes from.
When the join doesn't match, hlp_callsign will be NULL, which you can check for in PHP and use to color the row/cell red.
0
 

Author Comment

by:kevandju
ID: 33621857
Thank you that worked perfectly and I understand what you mean about the Aliases.
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.

Join & Write a Comment

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Creating and Managing Databases with phpMyAdmin in cPanel.
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 count occurrences of each item in an array.

746 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

11 Experts available now in Live!

Get 1:1 Help Now