それで昨日、php、Javascript、html を学ぶことにしました。ターミナルでphp5を使用して実行すると正しい出力が得られるphpスクリプトを作成しましたが、Javascriptを使用してWebページに追加しようとすると、コードの最後の〜1/4のビットと断片がテーブルとともに出力されます印刷しようとしましたが、変数値がありませんでした。スクリプトから echo のすべてのインスタンスを削除しても、これは行われます。
これがphpです:
<?php
$foo = $_GET["t"];
$con = mysql_connect('host', 'user', 'pw');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('db', $con);
if (!$db_selected)
{
die('Can\'t use db: ' . mysql_error());
}
$sql = sprintf("SELECT fun FROM table WHERE op = '%s'", $foo);
$data = mysql_query($sql);
$result = array();
$i = 0;
while($row = mysql_fetch_array($data)){
$result[$i] = $row[0];
$i++;
}
$dist = $name = range(min($result), max($result), .5);
for($i=0; $i<count($dist); $i++)
{
$temp = array_fill(0,count($result),0);
for($j=0; $j<count($result); $j++)
{
if ($result[$j] < $dist[$i]) $temp[$j] = 1;
}
$dist[$i] = array_sum($temp)/count($temp);
}
$temp = array_fill(0,count($dist),0);
for($i=0; $i<count($dist); $i++)
{
if ($dist[$i] < 0.5) $temp[$i] = 1;
}
$best = $name[array_sum($temp)-1];
$less = 0;
$more = 0;
$temp = array_fill(0, count($result), 0);
for($i=0; $i<count($result); $i++)
{
if ($result[$i] < $best) $temp[$i] = 1;
}
$less = array_sum($temp)/count($temp);
$temp = array_fill(0, count($result), 0);
for($i=0; $i<count($result); $i++)
{
if ($result[$i] > $best) $temp[$i] = 1;
}
$more = array_sum($temp)/count($temp);
$equal = 1 - $less - $more;
echo "<table border='1'>
<tr>
<th>Best</th>
<th>Less</th>
<th>Equal</th>
<th>More</th>
</tr>";
echo "<tr>";
echo "<td> $best </td>";
echo "<td> $less </td>";
echo "<td> $equal </td>";
echo "<td> $more </td>";
echo "</tr>";
echo "</table>";
mysql_close($con);
?>
そして私が得る出力。
$best) $temp[$i] = 1; $more = array_sum($temp)/count($temp); $equal = 1 - $less - $more; echo " Best Less Equal More "; エコー ""; echo "$best"; エコー " $less "; エコー " $equal "; エコー " $more "; エコー ""; エコー ""; mysql_close($con); ?>
ターミナルで任意の入力値でphp5を実行したときの出力は次のとおりです。
<table border='1'>
<tr>
<th>Best</th>
<th>Less</th>
<th>Equal</th>
<th>More</th>
</tr><tr><td> 27 </td><td> 0.48417721518987 </td><td> 0.048523206751055 </td><td> 0.46729957805907 </td></tr></table>
これは私が欲しいものです。
役立つ場合は、html/javascript を参照してください。
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function hreCalc(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","funCalc.php?t="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="totals" onchange="hreCalc(this.value)">
<option value="">Select a total:</option>
<option value="5.5">5.5</option>
<option value="6">6</option>
<option value="6.5">6.5</option>
<option value="8.5">8.5</option>
</select>
</form>
<br></br>
<div id="txtHint"><b>Total info will be listed here.</b></div>
</body>
</html>
私はこれらの言語を学び始めたばかりで、考えられることはすべて試しました。問題は > サインから来ているようですが、それを修正する方法がわかりません。私が知る限り、HTML で問題を引き起こすことなく、PHP で > を使用できるはずです。ubuntu 12.04を使用しているので、必要なものがすべてインストールされていない可能性がありますか?