2011-06-23 31 views
1

短版: $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 <[email protected]> 
*/ 
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([email protected]_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']; 
[email protected]_query($sql2,$dbh) or die('sql2: '.mysql_error($dbh)); 
while([email protected]_fetch_array($result2,MYSQL_ASSOC)){ 
$sql3='SELECT * FROM '.TABLE_PREFIX.'drawings WHERE drawingID="'.$row2['drawingID'].'" 
ORDER BY review DESC'; 
[email protected]_query($sql3,$dbh) or die('sql3: '.mysql_error($dbh)); 
[email protected]_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>'); 
[email protected]_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>'); 
[email protected]_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].')'; 
[email protected]_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'; 
[email protected]_query($sql2,$dbh) or die('sql2: '.mysql_error($dbh)); 
echo($sql2.'<br>'); 
$sql3='SELECT * FROM '.TABLE_PREFIX.'drawinglist_row WHERE drawinglist_rowID='[email protected]_result($result2,0,'drawinglist_rowID'); 
echo($sql3.'<br>'); 
[email protected]_query($sql3,$dbh) or die('sql3: '.mysql_error($dbh)); 
$sql4='SELECT machinetype FROM '.TABLE_PREFIX.'drawinglist WHERE 
drawinglistID='[email protected]_result($result3,0,'drawinglistID'); 
[email protected]_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: '[email protected]_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([email protected]_fetch_array($result2,MYSQL_ASSOC)){ 
$sql5='SELECT * FROM '.TABLE_PREFIX.'drawinglist_row WHERE 
drawinglist_rowID='.$row2['drawinglist_rowID']; 
[email protected]_query($sql5,$dbh) or die('sql5: '.mysql_error($dbh)); 
[email protected]_fetch_array($result5,MYSQL_ASSOC); 
$sql6='SELECT designation, review FROM '.TABLE_PREFIX.'drawings WHERE 
drawingID="'.$row5['drawingID'].'" ORDER BY review DESC'; 
[email protected]_query($sql6, $dbh) or die('sql6: '.mysql_error($dbh)); 
[email protected]_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'; 

[email protected]_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([email protected]_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> 
'); 
} 
?> 
+0

代碼審查是唯一的工作代碼。這在堆棧溢出上更合適,並且我已將其標記爲這樣。 –

回答

1
112: $count=count($drwlist_rowID); 

什麼是$drwlist_rowID?它似乎並沒有被定義...

+0

或'$ count = count($ machinenr);'! – Darkzaelus

+1

似乎頁自稱是幾次進入電影不同的形式,我猜$ drwlist_rowID應該從複選框得到在線82編輯:讓$ drwlist_rowID = $ _REQUEST [「drwlist_rowID」]似乎解決這個問題 – remuladgryta