我的问题涉及根据特定条件加入数据。
例如,在表A中有一个名为user_type的列。如果user_type为1,我想从表B中进行INNER JOIN。但是,如果表A中的user_type为2,我想从表C中进行INNER JOIN。
非常感谢有人可以在PHP中解决语法问题: - )
答案 0 :(得分:2)
像往常一样对两个表使用INNER JOIN,并使用CASE语句只显示表B或表C结果。
<style>
* {
box-sizing: border-box;
}
#myInput {
background-image: url(https://2.bp.blogspot.com/aLGnJhijsnc1qA-luOZiF6hsXFH7osaiVhthJf8Kt35FvecKGha7kbey-zbzbe-o0KSMEw=s400);
background-position: 5px 5px;
background-repeat: no-repeat;
background-color: #232323;
color: #FFFFFF;
width: 100%;
font-size: 28px;
padding: 6px 5px 6px 10px;
}
#myInputBorde {
border: 1px solid #ff9999;
padding: 1px;
}
#myUL {
list-style-type: none;
padding: 0;
margin: 0;
}
#myUL li a.header {
font-size: 24px;
}
#myUL li a {
border: 1px solid #141414;
margin-top: -1px;
/* Prevent double borders */
background-color: #8A8A8A;
padding: 7px;
text-decoration: none;
font-size: 16px;
color: #FFFFFF;
display: block
}
#myUL li a.header {
background-color: #454545;
cursor: default;
}
#myUL li a:hover:not(.header) {
background-color: #525252;
}
</style>
<div class="separator" style="clear: both; text-align: center;">
<a href="#https://2.bp.blogspot.com/-hmJ2cUx8GFc/V8WyozvS_KI/AAAAAAAAAO0/E_mnK1gELu0YMudfgDXt5w1VDj9103cegCLcB/s1600/merengue.jpg" style="margin-left: 1em; margin-right: 1em;"> <img border="0" height="162" alt="Merengue" src="https://2.bp.blogspot.com/-hmJ2cUx8GFc/V8WyozvS_KI/AAAAAAAAAO0/E_mnK1gELu0YMudfgDXt5w1VDj9103cegCLcB/s320/merengue.jpg" width="320" /></a>
</div>
<div style="text-align: center;"> <br />
<div style="text-align: center;">
<div id="myInputBorde"> <input type="text" id="myInput" onkeyup="myFunction()" placeholder="Introducir nombre de cantante"> </div>
<ul id="myUL">
<!-- AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -->
<li><a href="##" class="header">A</a></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Alex Bueno</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Amarfis</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Angelito Villalona</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Aramis Camilo</a></span></b></li>
<!-- BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB -->
<li><a href="##" class="header">B</a></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Benny Sadel</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Big Swing</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Bonny Cepeda</a></span></b></li>
<!-- CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC -->
<li><a href="##" class="header">C</a></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Charlie Rodriguez</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Cheche Abreu</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Cherito</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Chiqui Rodriguez</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Chuky Acosta</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Coco Band</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Cuco Valoy</a></span></b></li>
<!-- DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD -->
<li><a href="##" class="header">D</a></li>
<!-- EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE -->
<li><a href="##" class="header">E</a></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">El Jeffrey</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">El Zafiro</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Elvis Crespo</a></span></b></li>
<!-- FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -->
<li><a href="##" class="header">F</a></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Fausto Rey</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Felix Cumbe</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Fenix Ortiz</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Fernando Villalona</a></span></b></li>
<!-- GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG -->
<li><a href="##" class="header">G</a></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Hector Acosta</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Grupo Tambo</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Grupo Mania</a></span></b></li>
<!-- HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH -->
<li><a href="##" class="header">H</a></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Henry Garcia</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Henry Hierro</a></span></b></li>
<!-- IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII -->
<li><a href="##" class="header">I</a></li>
<!-- JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ -->
<li><a href="##" class="header">J</a></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Jacubanda</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Joseph Fonseca</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Jossie Esteban</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">July Mateo Rasputin</a></span></b> </li>
<!-- KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK -->
<li><a href="##" class="header">K</a></li>
<!-- LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL -->
<li><a href="##" class="header">L</a></li>
<li><span style="font-size: large;"><b><a href="#" target="_blank">La Gran Manzana</a></b></span></li>
<li><span style="font-size: large;"><b><a href="#" target="_blank">La Linea</a></b></span></li>
<li><span style="font-size: large;"><b><a href="#" target="_blank">La Makina</a></b></span></li>
<li><span style="font-size: large;"><b><a href="#" target="_blank">La Orquesta Joven</a></b></span></li>
<li><span style="font-size: large;"><b><a href="#" target="_blank">Las Chicas del Can</a></b></span></li>
<li><span style="font-size: large;"><b><a href="#" target="_blank">Lokera</a></b></span></li>
<li><span style="font-size: large;"><b><a href="#" target="_blank">Los Hermanos Rosarios</a></b></span></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Los Hijos de Puerto Rico</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Los Kenton</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Los Potros</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Los Sabrosos del Merengue</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Los Toros Band</a></span></b></li>
<!-- MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM -->
<li><a href="##" class="header">M</a></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Manny Manuel</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Miram Cruz</a></span></b></li>
<!-- NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN -->
<li><a href="##" class="header">N</a></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Nelson Cordero El Varon</a></span></b></li>
<!-- OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO -->
<li><a href="##" class="header">O</a></li>
<!-- PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP -->
<li><a href="##" class="header">P</a></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Peña Suazo</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Peter Cruz</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Popurri Clasico</a></span></b></li>
<!-- QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ -->
<li><a href="##" class="header">Q</a></li>
<!-- RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR -->
<li><a href="##" class="header">R</a></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Raffy Matias</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Ramon Orlando</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Ray Polanco</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Rubby Perez</a></span></b></li>
<!-- SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS -->
<li><a href="##" class="header">S</a></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Sandy Reyes</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Sergio Vargas</a></span></b></li>
<!-- TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT -->
<li><a href="##" class="header">T</a></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Tempo Dominicano</a></span></b></li>
<li><b><span style="font-size: large;"><a href="#" target="_blank">Toño Rosario</a></span></b></li>
<!-- UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU -->
<li><a href="##" class="header">U</a></li>
<!-- VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV -->
<li><a href="##" class="header">V</a></li>
<!-- WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW -->
<li><a href="##" class="header">W</a></li>
<li><b><a href="#" target="_blank"><span style="font-size: large;">Wilfrido Vargas</span></a></b></li>
<!-- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -->
<li><a href="##" class="header">X</a></li>
<!-- YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY -->
<li><a href="##" class="header">Y</a></li>
<!-- ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ -->
<li><a href="##" class="header">Z</a></li>
</ul>
</div>
</div>
<script>
function myFunction() {
var input, filter, ul, li, a, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
ul = document.getElementById("myUL");
li = ul.getElementsByTagName("li");
for (i = 0; i < li.length; i++) {
a = li[i].getElementsByTagName("a")[0];
if (a.innerHTML.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = "";
} else {
li[i].style.display = "none";
}
}
}
</script>