Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
Colocar valores de base de datos de una sola columna en una matriz y luego llamarlos en otra consulta

Tengo problemas para extraer información de la base de datos de la columna 'rownum' y colocarla en una matriz y luego usar esa información de la matriz para mi próxima consulta que selecciona aleatoriamente una línea de la matriz y luego la muestra.

 <?php // Connect to database include 'DB.php'; $con = mysqli_connect($host,$user,$pass); $dbs = mysqli_select_db($databaseName, $con); // Select Rownum to get numbers and only where there is no value in seen. $firstquery = "SELECT rownum FROM num_image WHERE seen=''"; // If there are results store them here $result = mysqli_query($firstquery) or die ("no query"); // Put the results taken from the table into array so it displays as: array(56, 44, 78, ...) etc... $result_array = array(); while($row = mysqli_fetch_assoc($result)) { $result_array[] = $row; } // Select the data I require $query = mysqli_query("SELECT number, association, image_file, skeleton, sound, colour, comments FROM num_image WHERE rownum='$row' LIMIT 1;"); $test = mysqli_query("UPDATE num_image SET Seen='yes' WHERE rownum='$row';"); // Fetch Results of Query, Ignore test. $arrayss = mysqli_fetch_row($query); // Echo Results as a Json echo json_encode($arrayss); ?>

No estoy seguro de lo que he hecho mal? ¿Se debe hacer eco de la matriz y luego mi línea $query lo llama en su lugar?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Código actualizado - Resuelto mi problema

Gracias por los consejos, muchachos, me ayudaron a comprenderlo y se me ocurrió una solución funcional.

 <?php // Connect to database include 'DB.php'; $con = mysqli_connect($host,$user,$pass); $dbs = mysqli_select_db($databaseName, $con); // Select Rownum to get numbers and only where there is no value in seen. $firstquery = "SELECT rownum FROM num_image WHERE seen=''"; // If there are results store them here $result = mysqli_query($firstquery) or die ("no query"); // Put the results taken from the table into array so it displays as: array(56, 44, 78, ...) etc... $result_array = array(); while($row = mysqli_fetch_assoc($result)) { $result_array[] = $row; } for ($i = 0; $i < count($result_array); $i++) { $all_rownums[] = implode(',', $result_array[$i]); } //pick a random point in the array $random = mt_rand(0,count($all_rownums)-1); //store the random question $question = $all_rownums[$random]; // Select the data I require $query = mysqli_query("SELECT number, association, image_file, skeleton, sound, colour, comments FROM num_image WHERE rownum='$question' LIMIT 1;"); $test = mysqli_query("UPDATE num_image SET Seen='yes' WHERE rownum='$question';"); // Fetch Results of Query, Ignore test. $arrayss = mysqli_fetch_row($query); // Echo Results as a Json echo json_encode($arrayss); ?>

Esta parte es lo que me ayudó a resolverlo:

 for ($i = 0; $i < count($result_array); $i++) { $all_rownums[] = implode(',', $result_array[$i]); }

Danza feliz

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!