Quizzes & Puzzles6 mins ago
Problem With Php Script: For, While And Mysqli_Fetch_Array
0 Answers
Hi, I have an PHP script that start like this:
for ($x = 2; $x sheets[0]["cells"]); $x++) {
$familia = $data->sheets[0]["cells"][$x][1];
$subfamilia = $data->sheets[0]["cells"][$x][2];
$categoria = $data->sheets[0]["cells"][$x][3];
$subcategoria = $data->sheets[0]["cells"][$x][4];
$marca = $data->sheets[0]["cells"][$x][5];
$serie = $data->sheets[0]["cells"][$x][6];
$referencia = $data->sheets[0]["cells"][$x][7];
Then I need to insert values like this:
$re_s_mar = mysqli_query($dbc, "SELECT `id`, `marca` FROM `psm_gescom_articulos_marcas` WHERE `marca` = '$marca' LIMIT 0,1");
while($row_s_mar = mysqli_fetch_array($re_s_mar)) {
$id_mar = $row_s_mar['id'];
$mar_mar = $row_s_mar['marca'];
if(empty($mar_mar)){
$res_i_mar = mysqli_query($dbc, "INSERT INTO `psm_gescom_articulos_marcas` (`marca`) VALUES ('$marca')");
if(mysqli_affected_rows($dbc)>0){$rows = 1;}
}
}
But don´t let me do it, Just insert the fisrt value or none.
for ($x = 2; $x sheets[0]["cells"]); $x++) {
$familia = $data->sheets[0]["cells"][$x][1];
$subfamilia = $data->sheets[0]["cells"][$x][2];
$categoria = $data->sheets[0]["cells"][$x][3];
$subcategoria = $data->sheets[0]["cells"][$x][4];
$marca = $data->sheets[0]["cells"][$x][5];
$serie = $data->sheets[0]["cells"][$x][6];
$referencia = $data->sheets[0]["cells"][$x][7];
Then I need to insert values like this:
$re_s_mar = mysqli_query($dbc, "SELECT `id`, `marca` FROM `psm_gescom_articulos_marcas` WHERE `marca` = '$marca' LIMIT 0,1");
while($row_s_mar = mysqli_fetch_array($re_s_mar)) {
$id_mar = $row_s_mar['id'];
$mar_mar = $row_s_mar['marca'];
if(empty($mar_mar)){
$res_i_mar = mysqli_query($dbc, "INSERT INTO `psm_gescom_articulos_marcas` (`marca`) VALUES ('$marca')");
if(mysqli_affected_rows($dbc)>0){$rows = 1;}
}
}
But don´t let me do it, Just insert the fisrt value or none.
Answers
Best Answer
Nobody has yet answered this question. Once some answers have been given, hsosaj will be able to select one answer as the best. Once a best answer has been selected, it will be shown here.
For more on marking an answer as the "Best Answer", please visit our FAQ.There are no answers available for this question.
Related Questions
Sorry, we can't find any related questions. Try using the search bar at the top of the page to search for some keywords, or choose a topic and submit your own question.