¿Por qué mi código php no recupera el campo que quiero de los resultados de mysql?
Frecuentes
Visto 49 veces
1
I am a beginner in php and mysql. I am trying to extract a particular field from a query result called "tweet_id
" and send it as a parameter to a constructor of class "Tweet
". The problem is the constructor seems to only recognize an empty string being passed to it. Why does my code not pass the correct tweet_id
? Am I somehow getting a hold of the record wrong?
$myquery = "select tweet_id from tweets";
$result = $DB->query($myquery);
while($row = $result->fetch_assoc())
{
}
$tweet = new Tweet($row["tweet_id"];
1 Respuestas
1
Lots Of bugs:
- Estas estableciendo
$tweet
fuera de tuwhile
loops $tweet
falta el$
variable prefix- Lots of missing closing parentheses
)
Try this and see if it fixes everything for you:
$myquery = "SELECT tweet_id FROM tweets";
$result = $DB->query($myquery);
while($row = $result->fetch_assoc()) {
$tweet = new Tweet($row["tweet_id"]);
print_r($tweet);
}
Respondido el 08 de diciembre de 12 a las 13:12
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas php sql or haz tu propia pregunta.
¿Qué biblioteca de base de datos estás usando? - prodigitalson
OP, Did my answer below help you? If it did, would you mind giving me a checkmark? - Steven Moseley