Im trying to loop through a recordset of class numbers to then query supplies from another recordset using mysql and php -
i have these recordsets i'm faking $_post in between queries utilize values first query values sec query, in manner first row of many, i've tried foreach loop in-between queries , fail...
how loop through first recorset rows many returned?.... code is:
$maxrows_rs_all_classes = 50; $pagenum_rs_all_classes = 0; if (isset($_get['pagenum_rs_all_classes'])) { $pagenum_rs_all_classes = $_get['pagenum_rs_all_classes']; } $startrow_rs_all_classes = $pagenum_rs_all_classes * $maxrows_rs_all_classes; mysql_select_db($database_conn_studiogear_mgr, $conn_studiogear_mgr); $query_rs_all_classes = "select sg_class_desc.class_image, sg_class_desc.class_location, sg_classes.class_name, sg_class_desc.class_room, sg_classes.class_cat1, sg_classes.class_cat2, sg_classes.class_cat3, sg_classes.class_id sg_class_desc inner bring together sg_classes on sg_class_desc.class_id = sg_classes.class_id"; $query_limit_rs_all_classes = sprintf("%s limit %d, %d", $query_rs_all_classes, $startrow_rs_all_classes, $maxrows_rs_all_classes); $rs_all_classes = mysql_query($query_limit_rs_all_classes, $conn_studiogear_mgr) or die (mysql_error()); $row_rs_all_classes = mysql_fetch_assoc($rs_all_classes); if (isset($_get['totalrows_rs_all_classes'])) { $totalrows_rs_all_classes = $_get['totalrows_rs_all_classes']; } else { $all_rs_all_classes = mysql_query($query_rs_all_classes, $conn_studiogear_mgr); $totalrows_rs_all_classes = mysql_num_rows($all_rs_all_classes); } $totalpages_rs_all_classes = ceil($totalrows_rs_all_classes/$maxrows_rs_all_classes)-1; $_post['class_id'] = $row_rs_all_classes['class_id']; //without next loop homecoming first row , sec query works first row // start loop when utilize loop, "array" echoed out , next query not run $classes = $row_rs_all_classes['class_id']; // recordset above foreach ($classes $value) { $arrayclasses[] = "".$value .""; echo $arrayclasses; // } // end loop $colname_rs_gear = "-1"; if (isset($_post['class_id'])) { $colname_rs_gear = $_post['class_id']; } mysql_select_db($database_conn_prestashop, $conn_prestashop); $query_rs_gear = sprintf("select ps_product_lang.name, ps_product.id_product, ps_product.price, ps_product.reference, ps_product_lang.description_short, ps_product_lang.description, ps_supplier.name, sg_class_gear.class_gear_image, sg_class_gear.class_gear_product_link ps_product inner bring together ps_product_lang on ps_product.id_product = ps_product_lang.id_product inner bring together ps_supplier on ps_product.id_supplier = ps_supplier.id_supplier inner bring together sg_class_gear on sg_class_gear.class_gear_pid = ps_product.id_product ps_product.id_product = sg_class_gear.class_gear_pid , sg_class_gear.class_id = %s", getsqlvaluestring($colname_rs_gear, "int")); $rs_gear = mysql_query($query_rs_gear, $conn_prestashop) or die(mysql_error()); $row_rs_gear = mysql_fetch_assoc($rs_gear); $totalrows_rs_gear = mysql_num_rows($rs_gear);
1) vulnerable sql injection attacks
2) using obsolete database library (mysql) , should switch mysqli or pdo
3) mysql_fetch_*() functions homecoming single row of info result set. since you're not calling mysql_fetch_in loop initial query, ever first row of results. code should be
$result = mysql_query($first_query_sql); while($row = mysql_fetch_assoc($result)) { $result2 = mysql_query($inner_query_sql); while($row2 = ...) { } }
php mysql loops recordset
No comments:
Post a Comment