put a link to in an echo

0

Good morning,

It turns out that in a .php file I receive a request through ajax and then fill a table in another file with the records found according to the parameter, everything works great. First of all, this is important, my .php file which makes the query and fills the table is a fixed route, for example: misitio.com/consultas/consultar_datos.php

In a field of the query I have the path of a photo that the user previously uploaded by means of another script, which has been, for example: misitio.com/uploads/foto13.jpg

What I want is that when I fill in the table, as I say, everything works correctly, when I put the link in the cell, I can place a label that says see a photo and so I open the image, the problem is that the link is as follows: misitio.com/consultas/misitio.com/uploads/foto13.jpg

ie, it takes the folder in which the .php file is, and it concatenates it with the link that is in the mysql field: misitio.com/consultas + misitio.com/uploads/foto13.jpg

here the code of the complete php file:

<?php
include '../PHP/conectar.php';

//hago la consulta
$result = mysqli_query($conexion,"select * from solicitudes WHERE estado='Solicitado' and tipo_solicitud='revision_tecnica'");

echo "<table>
<tr>
  <th align='center'>Nombre</th>
  <th align='center'>Comentarios</th>
  <th align='center'>Foto</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
  echo "<tr>";     
    echo "<td align='center'>" . $row['nombre'] . "</td>";
    echo "<td align='center'>".$row['comentarios']."</td>";      

    //aqui es donde esta mal
    $ruta=$row['ruta_foto'];
    echo "<td align='center'><a href='$ruta'>Ver foto</a></td>";

    //ya he intentado asi
    //echo "<td align='center'><a href='".$ruta."'>Ver foto</a></td>";

    //tambien intenté asi, sin guardar en variable
    //echo "<td align='center'><a href='$row['ruta_foto']'>Ver foto</a></td>";

  echo "</tr>";
}
echo "</table>";
mysqli_close($conexion);
?>

if you are wondering, I already checked that in mySql if the link is saved well, that is% misitio.com/uploads/foto13.jpg for the example

Any ideas?

Thank you!

    
asked by Gabriel Uribe Gomez 31.05.2018 в 01:01
source

2 answers

1

The problem is that you need to concatenate a / before putting your link in the following way:

PHP :

echo '<td align="center"><a href="/'.$ruta.'">Ver foto</a></td>';

I reversed the quotes to make it easier to understand and accommodate, what happened with that is that without the diagonal you say the route is after your current route and putting the diagonal You say it's going to be a totally new route .

Even if it does not work with 1 diagonal you can try concatenating 2 diagonals in the following way:

PHP:

echo '<td align="center"><a href="//'.$ruta.'">Ver foto</a></td>';

Greetings!

    
answered by 31.05.2018 / 01:24
source
0

You could try NOT to save the domain in your file path, so it would be saved in the DB as /uploads/foto13.jpg instead of misitio.com/uploads/foto13.jpg

then on the return of <a> leave the route you currently have, staying as

echo "<td align='center'><a href=".$row['ruta_foto'].">Ver foto</a></td>";

That should result in something like

<td align='center'><a href='/uploads/foto13.jpg'>Ver foto</a></td>

That the browser would interpret as

<td align='center'><a href='misitio.com/consultas/misitio.com/uploads/foto13.jpg'>Ver foto</a></td>
    
answered by 31.05.2018 в 01:14