Using 'OR' in mysql query.
I want to print the cell name of the table by which mean I get the data.
e.g
SELECT * FROM routes where stop_1='cityA' OR stop_2='CityA' OR stop_3='CityA' OR stop_1='cityB' OR stop_2='CityB' OR stop_3='CityB'
If query runs by CityA
, I want to know that cityA, is which stop? stop_1
, stop_2
, stop_3
?
I want to know CityA
is stop_1
or stop_2
or stop_3
?
<?php
$sql = "SELECT * FROM routes where stop_1='cityA' OR stop_2='CityA' OR stop_3='CityA' OR stop_1='cityB' OR stop_2='CityB' OR stop_3='CityB'";
if ($result = mysqli_query($con, $sql))
{
// Get field information for all fields
while ($fieldinfo = mysqli_fetch_field($result))
{
printf("Name: %s
", $fieldinfo->name);
printf("Table: %s
", $fieldinfo->table);
printf("max. Len: %d
", $fieldinfo->max_length);
}
// Free result set
mysqli_free_result($result);
}
?>
You could use case when
SELECT
case when stop_1='cityA' then 'stop_1' end check_stop_1_A
, case when stop_2='cityA' then 'stop_2' end check_stop_2_A
, case when stop_3='cityA' then 'stop_3' end check_stop_3_A
, case when stop_1='cityB' then 'stop_1' end check_stop_1_B
, case when stop_2='cityB' then 'stop_2' end check_stop_2_B
, case when stop_3='cityB' then 'stop_3' end check_stop_3_B
FROM routes
where stop_1='cityA'
OR stop_2='CityA'
OR stop_3='CityA'
OR stop_1='cityB'
OR stop_2='CityB'
OR stop_3='CityB'
I want to know the stop name?
$sql=mysql_query("SELECT * FROM service WHERE stop1='".$dep."' OR stop2='".$dep."' OR stop3='".$dep."' OR stop4='".$dep."' OR stop5='".$dep."' OR stop6='".$dep."' OR stop7='".$dep."' OR stop8='".$dep."' OR stop9='".$dep."' OR stop10='".$dep."' OR stop11='".$dep."' OR stop12='".$dep."' OR stop13='".$dep."' OR stop14='".$dep."' OR stop15='".$dep."' OR stop1='".$des."' OR stop2='".$des."' OR stop3='".$des."' OR stop4='".$des."' OR stop5='".$des."' OR stop6='".$des."' OR stop7='".$des."' OR stop8='".$des."' OR stop9='".$des."' OR stop10='".$des."' OR stop11='".$des."' OR stop12='".$des."' OR stop13='".$des."' OR stop14='".$des."' OR stop15='".$des."' ");