select data from two tables without mysql relation

1

I am creating a form to update data, I bring the information from the table escolar called T1 to update it, and another table ge_jornada called T2 that does not has relation with T1, I genre again the options for a dropdown, which already shows the saved day, and must show the alternative options that are in T2 .

Table 1 = school = T1

id | alumno | acudiente | direccion | tarifa  | placa  | jornada |
------------------------------------------------------------------
 1 | juan   | Maria     | Calle 107 | $80.000 | TTY521 | A       |
------------------------------------------------------------------
 2 | pablo  | Lina      | Calle 47  | $90.000 | TTY521 | B       |

Table 2 = ge_jornada = T2 this table is to build the dropdown

id | jornada |
--------------
 1 | A       |
--------------
 2 | B       |
--------------
 3 | Unica   |

I'm trying to get the data like this:

$con = mysqli_connect("*****", "user", "***", "BD") or die("Error " . mysqli_error($con));
    $query_edit = "SELECT t1.* FROM escolar as t1 WHERE t1.id='$editid' AND t1.placa = '$placa_id'
    CROSS JOIN    SELECT t2.jornada AS jos FROM ge_jornada as t2";

    $edit = mysqli_query( $con, $query_edit );
    $row = mysqli_fetch_row($edit);

My PHP form to update

<form class="form-horizontal" method="POST" action="actualizar.php" autocomplete="off">

<input type="text" class="form-control" id="direccion" name="direccion" placeholder="Direccion" value="<?php echo $row['t1.direccion']; ?>" required>

<select id="jornada"  class="js-select js-select-3" name="jornada" required>
<option value="<?php echo $row['t1.jornada']; ?>"><?php echo $row['t1.jornada']; ?></option>

<?php while ($row=mysqli_fetch_array($edit)) {
echo '<option value='.$row["t1.id"].'>'.$row["t2.jos"].'</option>';
}  mysqli_free_result($edit) ?>    
</select>
...

But I can not get the information to update, it does not load any data.

Thanks for the help I'm an apprentice.

    
asked by Andres Arango 21.07.2018 в 00:40
source

1 answer

0

You do not need to do everything in a query. You can do two separate queries and then set the value of the select like this:

$query_edit = "SELECT * FROM escolar WHERE id='$editid' AND placa = '$placa_id'";
$query2 = "SELECT jornada FROM ge_jornada";

$edit = mysqli_query( $con, $query_edit );
$edit2 = mysqli_query( $con, $query2 );
$row = mysqli_fetch_row($edit);

<form class="form-horizontal" method="POST" action="actualizar.php" autocomplete="off">

<input type="text" class="form-control" id="direccion" name="direccion" placeholder="Direccion" value="<?php echo $row['direccion']; ?>" required>

<select id="jornada"  class="js-select js-select-3" name="jornada" required>

<?php while ($row2=mysqli_fetch_array($edit2)) {
echo '<option value="'.$row2["id"].'"' . ($row['jornada'] == $row2['jornada'] ? ' selected' : '') .'>'.$row2["jornada"].'</option>';
}  mysqli_free_result($edit) ?>    
</select>
    
answered by 21.07.2018 / 00:44
source