gpt4 book ai didi

php - 难以捉摸的计数变量

转载 作者:行者123 更新时间:2023-11-29 00:55:04 28 4
gpt4 key购买 nike

简短版:$count 在下面的代码中似乎是 0,即使它不应该,为什么?

长版:前几天我的老板说“X 已经制作了一个程序来存储原理图,并发布了源代码。把它放在我们的内部网上”所以我开始想办法解决所有问题。来源是大约 25 个不同的 .php 文件和一张描述数据库表和关系的图片。错误是与下面的代码有关还是与其他东西有关?也许我只是因为漫长的一周感到疲倦而没有看到它。

代码:

    <?php
/**
* new_series.php
*
* Generates all the forms for creating a new series and machinenumbers.
* One form for selecting what drawinglists the serie should contain.
* One form for selecting what drawing the serie should contain and select
* a serienumber.
* One form for selecting machinnumbers.
* One form for listing all drawings with all information and number of
* copies that should be printed.
* This is where the function to automaticly print all drawings should be called
* when that function is availible.
*
* @author Emil Abrahamsson <emil@gavle.to>
*/
if(isset($_REQUEST['list_drw'])){
$info;
for($i=0;$i<20;$i++){
if(isset($_REQUEST['info'.$i]))
$info[$i]=$_REQUEST['info'.$i];
}
$sql1='SELECT * FROM '.TABLE_PREFIX.'drawinglist WHERE
machinetype="'.$_REQUEST['machinetype'].'"';
$result1=mysql_query($sql1,$dbh) or die('sql1: '.mysql_error($dbh));
$drwlists;

$j=0;
while($row1=@mysql_fetch_array($result1,MYSQL_ASSOC)){
foreach($info as $inf){
if($row1['info']==$inf){
$drwlists[$j]=$row1;
$j++;
}
}
}
echo('
<div class="text">
<form name="list_drw" id="list_drw" action="index.php" method="post">
<input type="hidden" name="page" id="page" value="new_series" />
<fieldset style="border:1px solid #783151;width: 355px;height:60px;">
<legend>Ange serienummer och antal:</legend>
<table>
<tr>
<td><label for="series">Serie:</label></td>
<td><input type="text" name="series" id="series" /></td>
<td><label for="quantity">Antal:</label></td>
<td><input type="text" name="quantity" id="quantity" /></td>
</tr>
</table>
</fieldset>
');
$counter=0;
foreach($drwlists as $list){
echo('
<table class="info" width="100%" style="border-bottom:2px solid">
<tr>
<td>Maskintyp: '.$list['machinetype'].'</td>
<td>Info: '.$list['info'].'</td>
<td>Datum: '.$list['date'].'</td>
</tr>
</table>
<table width="100%" style="border-collapse:collapse;text-align:center;" border="1">
<tr>
<td style="width:20px;">&nbsp;</td>
<td style="width:40px;"><label>Ritningsnr</label></td>
<td style="width:15px;"><label>Pos</label></td>
<td style="width:15px;"><label>Rev</label></td>
<td style="width:150px;"><label>Ben&auml;mning</label></td>
<td style="width:20px;"><label>St/m</label></td>
<td style="width:100px;"><label>Anm&auml;rkning</label></td>
</tr>
');
$sql2='SELECT * FROM '.TABLE_PREFIX.'drawinglist_row WHERE
drawinglistID='.$list['drawinglistID'];
$result2=@mysql_query($sql2,$dbh) or die('sql2: '.mysql_error($dbh));
while($row2=@mysql_fetch_array($result2,MYSQL_ASSOC)){
$sql3='SELECT * FROM '.TABLE_PREFIX.'drawings WHERE drawingID="'.$row2['drawingID'].'"
ORDER BY review DESC';
$result3=@mysql_query($sql3,$dbh) or die('sql3: '.mysql_error($dbh));
$row3=@mysql_fetch_array($result3,MYSQL_ASSOC);
echo('
<tr>
<td><input type="checkbox" name="drwlist_rowID[]" id="drwlist_rowID[]"
value="'.$row2['drawinglist_rowID'].'" checked="checked"></td>
<td>'.$row2['drawingID'].'</td>
<td>'.$row2['pos'].'</td>
<td>'.$row3['review'].'</td>
<td>'.$row3['designation'].'</td>
<td>'.$row2['stm'].'</td>
<td>'.$row2['observation'].'</td>
</tr>
');
}
echo('
</table>
');
}
echo('
<table width="100%">
<tr>
<td align="right"><input type="submit" name="new_series" id="new_series"
value="N&auml;sta" /></td>
</tr>

</table>
</form>
</div>
');
}else if(isset($_REQUEST['new_series'])){
//echo('NEW SERIES IS SET');
$count=count($drwlist_rowID);
for($i=0;$i<$_REQUEST['quantity'];$i++){
$sql='INSERT INTO '.TABLE_PREFIX.'series VALUES("'.$_REQUEST['series'].'",'.$_REQUEST['quantity'].', '.($i+1).')';
echo($sql.'</br></br>');
$result=@mysql_query($sql,$dbh) or die('sql: '.mysql_error($dbh));
echo($count);
for($j=0;$j<$count;$j++){
echo($j);
$sql2='INSERT INTO '.TABLE_PREFIX.'machinelist VALUES("'.$drwlist_rowID[$j].'", "'.$_REQUEST['series'].'", '.($i+1).')';
echo($sql2.'</br>');
$result2=@mysql_query($sql2,$dbh) or die('sql2: '.mysql_error($dbh));
}
}
echo('
<div class="text">
<form name="new_series" id="new_series" action="index.php" method="post">
<input type="hidden" name="page" id="page" value="new_series" />
<input type="hidden" name="series" id="series" value="'.$_REQUEST['series'].'" />
<input type="hidden" name="quantity" id="copies" value="'.$_REQUEST['quantity'].'" />
<fieldset style="border:1px solid #783151;width: 200px;">
<legend>Ange maskinnummer:</legend>
<table>
<tr>
<td>Serie</td>
<td>L&ouml;pnummer</td>
<td>Antal</td>
<td>Maskinnummer</td>
</tr>
');
for($i=0;$i<$_REQUEST['quantity'];$i++){
echo('
<tr>
<td>'.$_REQUEST['series'].'</td>
<td><input type="hidden" name="number[]" id="number[]" value="'.($i+1).'"
/>'.($i+1).'</td>
<td>'.$_REQUEST['quantity'].'</td>
<td><input type="text" name="machinenr[]" id="machinenr[]" /></td>
</tr>
');
}
echo('
<tr>
<td colspan="4" align="right"><input type="submit" name="create" id="create"
value="Skapa" /></td>
</table>
</form>
</div>
');
}else if(isset($_REQUEST['create'])){
$count=count($machinenr);
for($i=0;$i<$count;$i++){
if($machinenr[$i]!=''){
$sql='INSERT INTO '.TABLE_PREFIX.'machine VALUES ("'.$machinenr[$i].'",
"'.$_REQUEST['series'].'", '.$_REQUEST['quantity'].', '.$number[$i].')';
$result=@mysql_query($sql,$dbh) or die('sql: '.mysql_error($dbh));
}
}
$sql2 = 'SELECT drawinglist_rowID FROM '.TABLE_PREFIX.'machinelist WHERE
series="'.$_REQUEST['series'].'" GROUP BY drawinglist_rowID';
$result2=@mysql_query($sql2,$dbh) or die('sql2: '.mysql_error($dbh));
echo($sql2.'<br>');
$sql3='SELECT * FROM '.TABLE_PREFIX.'drawinglist_row WHERE drawinglist_rowID='.@mysql_result($result2,0,'drawinglist_rowID');
echo($sql3.'<br>');
$result3=@mysql_query($sql3,$dbh) or die('sql3: '.mysql_error($dbh));
$sql4='SELECT machinetype FROM '.TABLE_PREFIX.'drawinglist WHERE
drawinglistID='.@mysql_result($result3,0,'drawinglistID');
$result4=@mysql_query($sql4,$dbh) or die('sql4: '.mysql_error($dbh));
echo('
<div class="text">
<form name="print_drw" id="print_drw action="index.php" method="post">
<input type="hidden" name="page" id="page" value="new_series" />
<table class="info" width="100%" style="border-bottom:2px solid">
<tr>
<td>Maskintyp: '.@mysql_result($result4,0,'machinetype').'</td>
</tr>

</table>
<table width="100%" style="border-collapse:collapse;text-align:center;" border="1">
<tr>
<td style="width:40px;"><label>Ritningsnr</label></td>
<td style="width:15px;"><label>Pos</label></td>
<td style="width:15px;"><label>Rev</label></td>
<td style="width:150px;"><label>Ben&auml;mning</label></td>
<td style="width:20px;"><label>St/m</label></td>
<td style="width:100px;"><label>Anm&auml;rkning</label></td>
<td style="width:40px;"><label>PDF</label></td>
<td style="width:50px;"><label>Utskr. ant.</label></td>
</tr>
');
while($row2=@mysql_fetch_array($result2,MYSQL_ASSOC)){
$sql5='SELECT * FROM '.TABLE_PREFIX.'drawinglist_row WHERE
drawinglist_rowID='.$row2['drawinglist_rowID'];
$result5=@mysql_query($sql5,$dbh) or die('sql5: '.mysql_error($dbh));
$row5=@mysql_fetch_array($result5,MYSQL_ASSOC);
$sql6='SELECT designation, review FROM '.TABLE_PREFIX.'drawings WHERE
drawingID="'.$row5['drawingID'].'" ORDER BY review DESC';
$result6=@mysql_query($sql6, $dbh) or die('sql6: '.mysql_error($dbh));
$row6=@mysql_fetch_array($result6,MYSQL_ASSOC);
$type=substr(preg_replace("/[^0-9]/", '', $row5['drawingID']),0,1);
$no;
switch($type){
case '1':
case '2':
$no=4;
break;
case '3':
case '4'
:$no=3;
break;
}
echo('
<tr>
<td>'.$row5['drawingID'].'</td>
<td>'.$row5['pos'].'</td>
<td>'.$row6['review'].'</td>
<td>'.$row6['designation'].'</td>
<td>'.$row5['stm'].'</td>
<td>'.$row5['observation'].'</td>
<td>
');
$url= DRW_PATH.$row5['drawingID'].strtolower($row6['review']).'.pdf';
if(file_exists($url))
echo('<a href="'.$url.'" target="_blank">PDF</a><input type="hidden" name="url[]"
id="url[]" value="'.$url.'" />');
echo('
</td>
<td><input type="text" name="copies[]" id="copies[]" size="2" style="text-
align:center;" value="'.$no.'"/></td>
</tr>
');
}
/* Not functional yet */
/*
echo('
</table>
<table width="100%">
<tr>
<td align="right"><input type="submit" name="print" id="print" value="Skriv ut"
/></td>
</tr>
</table>
</form>
</div>
');
*/
echo('
</table>
</form>
</div>
');
}else{
$sql1='SELECT info FROM '.TABLE_PREFIX.'drawinglist WHERE
machinetype="'.$_REQUEST['machinetype'].'" GROUP BY info';

$result1=@mysql_query($sql1,$dbh) or die ('sql1: '.mysql_error($dbh));
echo('
<div class="text">
<form name="new_serie" id="new_serie" action="index.php" method="post">
<input type="hidden" name="page" id="page" value="new_series" />
<input type="hidden" name="machinetype" id="machinetype"
value="'.$_REQUEST['machinetype'].'" />
<table>
<tr>
<td colspan="2" class="machinetype">'.$_REQUEST['machinetype'].'</td>
</tr>
');
$j=0;
while($row1=@mysql_fetch_array($result1,MYSQL_ASSOC)){
echo('
<tr>
<td><font style="font-family:Verdana, sans-serif;font-size:14px;color:#000000;line-
height:25px;">'.$row1['info'].'</font></td>
<td><input type="checkbox" name="info'.$j.'" id="info'.$j.'" value="'.$row1['info'].'"
/></td>
</tr>
');
$j++;
}
echo('
<tr>
<td colspan="2" align="right"><input type="submit" name="list_drw" id="list_drw"
value="N&auml;sta" /></td>
</tr>
</table>
</form>
</div>
');
}
?>

最佳答案

112: $count=count($drwlist_rowID);

什么是$drwlist_rowID?好像没有定义...

关于php - 难以捉摸的计数变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6468116/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com