我有一個簡化的ajay腳本,從中刪除了所有不相關的代碼。我遇到的問題是首先與我的列數組和隨後的foreach循環。我想要遍歷每個元素,並將相應的元素更改爲YES(如果爲true),如果爲false,則將其更改爲NO,但我不明白爲什麼它不起作用。循環陣列問題
如果有任何問題,如語法錯誤或大括號等,它們是簡化我的代碼的問題,並不存在於我的機器上的版本。
<?php
$con = mysqli_connect("localhost", "", "", "");
if (!$con) {
echo "Can't connect to MySQL Server. Errorcode: %s\n". mysqli_connect_error();
exit;
}
$con->set_charset("utf8");
$query1 = 'SELECT EGGS, SALAD, TREES, REVISED FROM AUCTIONS WHERE ARTICLE_NO = ?';
if ($getRecords = $con->prepare($query1)) {
$getRecords->bind_param("s", $pk);
$getRecords->execute();
$getRecords->bind_result($EGGS, $SALAD, $TREES, $REVISED);
while ($getRecords->fetch()) {
$columns = array('EGGS', 'SALAD', 'TREES', 'REVISED');
foreach($columns as $column) {
$$column = $columns[$column] ? 'YES' : 'NO';
}
imageSize = imageResize($PIC_URL, 250, 300);
echo "<h1>".$EGGS."</h1>";
}
}
function imageResize($imageURL, $maxWidth, $maxHeight) {
$imageSize["width"] = 0;
$imageSize["height"] = 0;
$size = getimagesize($imageURL);
if ($size) {
$imageWidth = $size[0];
$imageHeight = $size[1];
$wRatio = $imageWidth/$maxWidth;
$hRatio = $imageHeight/$maxHeight;
$maxRatio = max($wRatio, $hRatio);
if ($maxRatio > 1) {
$imageSize["width"] = $imageWidth/$maxRatio;
$imageSize["height"] = $imageHeight/$maxRatio;
return $imageSize;
} else {
$imageSize["width"] = $imageWidth;
$imageSize["height"] = $imageHeight;
return $imageSize;
}
} else {
die(print_r(error_get_last()));
}
}
確實你現在將$ pk綁定到「s」而不是「i」,這意味着我對你的其他問題的提示是正確的嗎? – Alnitak 2009-02-05 16:47:05
是的,確切地說。我以爲我標記爲正確的? – 2009-02-06 09:47:17
你當時還沒有 - 但你現在有,謝謝! – Alnitak 2009-02-06 10:28:01