Php mysql_fetch_数组仅获取第一个结果,即使使用while循环也是如此
我正在尝试打印多个mysql行,使用mysql\u fetch\u array和while loop,但它只打印第一个结果,而我的表中包含了许多条件正确的结果Php mysql_fetch_数组仅获取第一个结果,即使使用while循环也是如此,php,mysql,arrays,while-loop,Php,Mysql,Arrays,While Loop,我正在尝试打印多个mysql行,使用mysql\u fetch\u array和while loop,但它只打印第一个结果,而我的表中包含了许多条件正确的结果 $queryString="SELECT * FROM items WHERE order_id='".$order_id."' and confirm_order='0' ORDER BY id"; $myquery=mysql_query($queryString); $handle = printer_open("POS"); p
$queryString="SELECT * FROM items WHERE order_id='".$order_id."' and confirm_order='0' ORDER BY id";
$myquery=mysql_query($queryString);
$handle = printer_open("POS");
printer_start_doc($handle, "My Document");
printer_start_page($handle);
$font = printer_create_font("Arial", 35, 20, 300, false, false, false, 0);
printer_select_font($handle, $font);
while ($fetch = mysql_fetch_array($myquery)) {
$product=$fetch[product_name];
$type=$fetch[type];
$q=$fetch[item_quantity];
$comment=$fetch[comment];
$tex="".$q." ".$type." ".$comment." ".$product."";
printer_draw_text($handle, $tex, 10, 10);
}
printer_delete_font($font);
printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);
注意:-我不能使用mysqli
或PDO
,因为我只是在基于
该函数使用所选字体在x、y位置绘制文本
在代码x中,y
值为10,10。所以每次新的文本都写在同一个位置上。这意味着上一个值被新值覆盖,只绘制一个值
有两种可能的解决方案:-
1.每次迭代后更改x、y位置值
$counter = 10; //add a number counter
while ($fetch = mysql_fetch_assoc($myquery)) {//use assoc for lighter array iteration
$product=$fetch['product_name']; //use quotes around indexes, best practise
$type=$fetch['type'];
$q=$fetch['item_quantity'];
$comment=$fetch['comment'];
$tex="$q $type $comment $product";//remove unncessary quotes
printer_draw_text($handle, $tex, $counter, $counter); // use that number counter as x,y position
$counter+10;//in each iteration chnage the value by adding 10
}
2.或在每次迭代中创建新页面:-
while ($fetch = mysql_fetch_assoc($myquery)) {//use assoc for lighter array iteration
$product=$fetch['product_name'];//use quotes around indexes, best practise
$type=$fetch['type'];
$q=$fetch['item_quantity'];
$comment=$fetch['comment'];
$tex="$q $type $comment $product";//remove unncessary quotes
printer_draw_text($handle, $tex, 10, 10);
printer_end_page($handle); //end page on each iteration
}
printer_delete_font($font);
printer_end_doc($handle);
printer_close($handle);
注意:-按原样添加其余代码。基于
该函数使用所选字体在x、y位置绘制文本
在代码x中,y
值为10,10。所以每次新的文本都写在同一个位置上。这意味着上一个值被新值覆盖,只绘制一个值
有两种可能的解决方案:-
1.每次迭代后更改x、y位置值
$counter = 10; //add a number counter
while ($fetch = mysql_fetch_assoc($myquery)) {//use assoc for lighter array iteration
$product=$fetch['product_name']; //use quotes around indexes, best practise
$type=$fetch['type'];
$q=$fetch['item_quantity'];
$comment=$fetch['comment'];
$tex="$q $type $comment $product";//remove unncessary quotes
printer_draw_text($handle, $tex, $counter, $counter); // use that number counter as x,y position
$counter+10;//in each iteration chnage the value by adding 10
}
2.或在每次迭代中创建新页面:-
while ($fetch = mysql_fetch_assoc($myquery)) {//use assoc for lighter array iteration
$product=$fetch['product_name'];//use quotes around indexes, best practise
$type=$fetch['type'];
$q=$fetch['item_quantity'];
$comment=$fetch['comment'];
$tex="$q $type $comment $product";//remove unncessary quotes
printer_draw_text($handle, $tex, 10, 10);
printer_end_page($handle); //end page on each iteration
}
printer_delete_font($font);
printer_end_doc($handle);
printer_close($handle);
注意:-按原样添加其余代码。(这是旁注,它不回答问题。)要查找错误和警告,请输入
错误报告(E|u ALL | E|u通知);在脚本前面
$product=$fetch[product_name]$type=$fetch[type]$q=$fetch[项目数量]$comment=$fetch[comment]代码>需要是:-$product=$fetch['product_name']$type=$fetch['type']$q=$fetch['item_quantity']$comment=$fetch['comment']代码>(这是旁注,它没有回答问题。)@AlivetoDie-不,他们没有。这是一个最佳实践,但不是一个需要。我看不出有任何理由循环不起作用。尝试查看或获取代码以输出纯文本,以防TeX库出现问题。(这是旁注,它没有回答问题。)要查找错误和警告,请输入错误报告(E|ALL | E|u通知);在脚本前面
$product=$fetch[product_name]$type=$fetch[type]$q=$fetch[项目数量]$comment=$fetch[comment]代码>需要是:-$product=$fetch['product_name']$type=$fetch['type']$q=$fetch['item_quantity']$comment=$fetch['comment']代码>(这是旁注,它没有回答问题。)@AlivetoDie-不,他们没有。这是一个最佳实践,但不是一个需要。我看不出有任何理由循环不起作用。尝试查看或获取代码以输出纯文本,以防您的TeX库出现问题。@SophieBernard很乐意帮助您:):@SophieBernard很乐意帮助您:):)