Die zweite Abfrage nicht funktioniert und ich bin versucht, alle in den Informationen in der zweiten Abfrage von einer anderen Tabelle Echo aber die nächste Meldung erscheint:
Undefined property: stdClass::$titulo
(und den Rest „resultado2“)
ich versuchte eine Weile, wie die erste Abfrage zu tun (while ($ nfila = $ resultado2-> fetch_object())), aber eine andere Fehlermeldung angezeigt wird:
Trying to get property of non-object
PHP. Undefinierte Eigenschaft: stdClass im Doppel Abfrage
<?php
$usuario = $_SESSION['usuario_valido'];
$consulta = "SELECT * FROM `lista-usuarios` WHERE categoria='favoritos' AND nombreusuario='$usuario' ORDER BY pelicula ASC";
$resultado = $conexion->query($consulta);
if ($resultado)
{
$cont3 = 1; //Para el id de la peli
$i = 0; //Para un class unico
while ($nfila = $resultado->fetch_object())
{
$pelicula = "peli" . $cont3; //Para hacer un id unico de cada pelicula
$i++;
echo "<form role='form' id='$pelicula'><table class='table table-striped'>";
echo "
<tr>
<td>" . $cont3 . "</td>
<td class='celda2'>" . $nfila->pelicula . "</td>
<td class='celda2'>" . $nfila->anio . "</td>
<td class='celda2'><button type='button' class='infoCompleta btn btn-default' data-toggle='modal'data-target='.modal" . $i . "'><span class='glyphicon glyphicon-hand-right'></span> Info Completa</button></td><td class='celda2'><button type='button' class='eliminarFav1 btn btn-danger'><span class='glyphicon glyphicon-remove-sign'> </span> Favoritos</button></td>
</tr>";
$consulta2 = "SELECT * FROM `peliculas` WHERE titulo='$nfila->pelicula'";
$resultado2 = $conexion->query($consulta2);
if ($resultado2)
{
echo "
<div class='modal fade bs-example-modal-lg modal" . $i . "' tabindex='-1' role='dialog' aria-labelledby='myLargeModalLabel'>
<div class='modal-dialog modal-lg'>
<div class='modal-content'>
<div class='modal-header'>
<button tyle='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
<h4 class='modal-tigle'>" . $nfila->titulo . "</h4>
</div>
<div class='modal-body'>
<center><a target='_blank' href='imagenes/" . $nfila->imagen . "'>
<img class='img-top-peliculas' src='imagenes/" . $nfila->imagen . "' class='img-rounded '></a>
</center><br />
<p><strong>Titulo Original: </strong>" . $nfila->tituloOriginal . "</p>
<p><strong>Año: </strong>" . $nfila->anio . "</p>
<p><strong>Duracion: </strong>" . $nfila->duracion . " min.</p>
<p><strong>País: </strong>" . $nfila->pais . "</p>
<p><strong>Director: </strong>" . $nfila->director . "</p>
<p><strong>Reparto: </strong>" . $nfila->reparto . "</p>
<p><strong>Género: </strong>" . $nfila->genero . "</p>
<p><strong>Sinopsis: </strong>" . $nfila->sinopsis . "</p>
</div>
<div class='modal-footer'>
<button type='button' class='btn btn-default' data-dismiss='modal'>Cerrar</button>
</div>
</div>
</div>
</div>";
}
echo "<input name='usuario' type='hidden' value='$usuario'>";
echo "<input name='titulo' type='hidden' value='$nfila->pelicula'>";
echo "<input name='anio' type='hidden' value='$nfila->anio'>";
echo "<input name='categoria' type='hidden' value='categoria' class='cat'>";
echo "</table></form>";
$cont3++;
}
echo "<span class='datos'></span>";
}
else
{
echo "Hubo un problema al cargar las peliculas";
}
Sie konvertieren Vielen es sehr viel funktioniert, möchte ich eine andere Frage stellen. Jemand sagte mir: " Dies wird eine Auswirkung auf die Leistung der Anwendung haben, weil die Schleife ausgeführt wird n Abfragen, abhängig von der Serverkonfiguration kann ihn werfen, vielleicht besser einen anderen Weg, dies zu tun". Es ist ein guter Weg, dies zu tun? Oder sollte ich es anders machen? – SilverSurfer
Ja, ich würde dies in einer einzigen verbundenen Abfrage tun, da Sie die '$ nfila-> pelicula' als Schlüssel in die zweite Tabelle verwenden. Sie können auch 2 aktive Abfragen für die gleiche Verbindung ausführen, also würde ich zumindest eine fetch_all() für das erste Abfrageergebnis machen und das Array, das liefert, iterieren. – Ray
Ok, aber denkst du, dass es ein Problem gibt, wie ich es tue? – SilverSurfer