PHucker
Новичок
Здравствуйте! У меня есть такой код:
и так до 30ти. из-за этого у меня он тормозит. Как укоротить его? Намекните. Я новичок в этом деле.
PHP:
$name = $_GET["name"];
if ($name == 1) {
$connect = mysql_connect("***********", "report_user", "*********");
$select = mysql_select_db("smartvend", $connect);
$result = mysql_query("SELECT history.MeterNum, fields.ID, history.FieldName, fields.Description, history.ExecDate, history.FieldValue
FROM
amr_fields fields, amr_read_history history
WHERE
fields.ID=history.FieldName AND ExecDate>= SUBDATE(CURRENT_DATE, INTERVAL 1 DAY)
",$connect);
while ($data = mysql_fetch_row($result))
{
echo"<tr>";
echo"<td>{$data[0]}</td>";
echo"<td>{$data[1]}</td>";
echo"<td>{$data[2]}</td>";
echo"<td>{$data[3]}</td>";
echo"<td>{$data[4]}</td>";
echo"<td>{$data[5]}</td>";
echo"</tr>";
}
}
else {
$connect = mysql_connect("************", "report_user", "****");
$select = mysql_select_db("smartvend", $connect);
$result = mysql_query("SELECT history.MeterNum, fields.ID, history.FieldName, fields.Description, history.ExecDate, history.FieldValue
FROM
amr_fields fields, amr_read_history history
WHERE
fields.ID=history.FieldName AND ExecDate>= '(CURDATE()'
",$connect);
while ($data = mysql_fetch_row($result))
{
echo"<tr>";
echo"<td>{$data[0]}</td>";
echo"<td>{$data[1]}</td>";
echo"<td>{$data[2]}</td>";
echo"<td>{$data[3]}</td>";
echo"<td>{$data[4]}</td>";
echo"<td>{$data[5]}</td>";
echo"</tr>";
}
}
$name = $_GET["name"];
if ($name == 2) {
$connect = mysql_connect("*******", "report_user", "**********");
$select = mysql_select_db("smartvend", $connect);
$result = mysql_query("SELECT history.MeterNum, fields.ID, history.FieldName, fields.Description, history.ExecDate, history.FieldValue
FROM
amr_fields fields, amr_read_history history
WHERE
fields.ID=history.FieldName AND ExecDate>= SUBDATE(CURRENT_DATE, INTERVAL 2 DAY)
",$connect);
while ($data = mysql_fetch_row($result))
{
echo"<tr>";
echo"<td>{$data[0]}</td>";
echo"<td>{$data[1]}</td>";
echo"<td>{$data[2]}</td>";
echo"<td>{$data[3]}</td>";
echo"<td>{$data[4]}</td>";
echo"<td>{$data[5]}</td>";
echo"</tr>";
}
}
else {
$connect = mysql_connect("********", "report_user", "**********");
$select = mysql_select_db("smartvend", $connect);
$result = mysql_query("SELECT history.MeterNum, fields.ID, history.FieldName, fields.Description, history.ExecDate, history.FieldValue
FROM
amr_fields fields, amr_read_history history
WHERE
fields.ID=history.FieldName AND ExecDate>= '(CURDATE()'
",$connect);
while ($data = mysql_fetch_row($result))
{
echo"<tr>";
echo"<td>{$data[0]}</td>";
echo"<td>{$data[1]}</td>";
echo"<td>{$data[2]}</td>";
echo"<td>{$data[3]}</td>";
echo"<td>{$data[4]}</td>";
echo"<td>{$data[5]}</td>";
echo"</tr>";
}
}
Последнее редактирование модератором: