gpt4 book ai didi

php - html页面中的数据库mysql

转载 作者:行者123 更新时间:2023-11-28 21:49:16 24 4
gpt4 key购买 nike

我试图将连接到我的 MySQL 数据库的 php 代码直接放在我的 HTML 页面中,但是当我尝试查看该页面时出了点问题。我如何解决错误“ fatal error :最长执行时间/membri/bestparty/IOS/IOS/eventi.php 第 41 行超过 30 秒”

如果我尝试删除一个变量,例如 $festa[$i],错误仍然存​​在。

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="HandheldFriendly" content="True">
<meta http-equiv="cleartype" content="on">
<link rel="stylesheet" type="text/css" href="css/stile.css">
<meta name="viewport" content="width=320, initial-scale=0.7, user-scalable=no">
<script src="JS/jquery-1.11.1.js.js"></script> <!--PER EVENTI-->
<script src="JS/func.js"></script> <!--PER EVENTI-->

<title>BParty</title>

</head>
<body>

<?
$DBhost = "localhost";
$DBuser = "bestparty";
$DBpass = "";
$DBName = "my_bestparty";

$table = "Dati";

mysql_connect($DBhost,$DBuser,$DBpass) or die("Impossibile collegarsi al server");
@mysql_select_db("$DBName") or die("Impossibile connettersi al database $DBName");



$sqlquery = "SELECT * FROM `Dati` ORDER BY Data DESC";
$result = mysql_query($sqlquery);
$number = mysql_num_rows($result);



$i = 0;


while ($i < 20) {

$festa[$i] = mysql_result($result,$i,"festa");
$luogo[$i] = mysql_result($result,$i,"luogo");
$idfesta[$i] = mysql_result($result,$i,"ID");
$data[$i] = mysql_result($result,$i,"data");
$foto[$i] = mysql_result($result,$i,"organizzatore");
}
?>

<div id="navigation">
<table width="100%">
<tr valign="middle">
<td valign="middle" width="25%" align="center">
<
</td>
<td valign="middle" width="50%" align="center">
BPARTY
</td>
<td width="25%" align="center">
>
</td>
</tr>
</table>
</div>

<div id="evntprg">
EVENTI IN PROGRAMMA
</div>

<div id="container" style="overflow:scroll;">
<? echo'
<!--INIZIO DIV EVENTO-->
<a href="http://www.bparty.org/IOS/IOS/pagevento.php?var=$idfesta[$i]">
<div style="width:90%; display:block; margin:0 auto;
padding-top:10px; margin-top:10px; padding-left:10px;
background-color:#FFF; padding-bottom:10px;
border-left:solid 8px #4D7C4F;">
<table width="100%" style=\'table-layout:fixed\'>
<tr valign="middle">
<td valign="middle" align="center" class="evntfoto"
style="background-image:url($foto[$i]);
background-position:center;
background-size: cover;">
</td>
<td valign="top" align="left" id="evnttxt">
&nbsp; &nbsp; <font color="#0066FF" size="+1"> <b> $festa[$i] </b></font> <br>
&nbsp; &nbsp; echo "$data[$i]" <br>
&nbsp; &nbsp; <font color="#585858"> $luogo[$i] </font> <br>
</td>
</tr>
</table>
</div></a>
<!--FINE DIV EVENTO-->
';
?>
</div>




</div>







</body>
</html>

--编辑--

好的,我解决了这个问题,但是现在..为什么 html 页面将变量显示为“$festa[$i]”而不是例如“Lorem ipsum”?

<?
$DBhost = "localhost";
$DBuser = "bestparty";
$DBpass = "";
$DBName = "my_bestparty";

$table = "Database";

mysql_connect($DBhost,$DBuser,$DBpass) or die("Impossibile collegarsi al server");
@mysql_select_db("$DBName") or die("Impossibile connettersi al database $DBName");



$sqlquery = "SELECT * FROM `Database` ORDER BY data DESC";
$result = mysql_query($sqlquery);
$number = mysql_num_rows($result);



$i = 0;

while ($i < 20) {

$festa[$i] = mysql_result($result,$i,"festa");
$luogo[$i] = mysql_result($result,$i,"luogo");
$idfesta[$i] = mysql_result($result,$i,"ID");
$data[$i] = mysql_result($result,$i,"data");
$linkfoto[$i] = mysql_result($result,$i,"organizzatore");
echo'
<!--INIZIO DIV EVENTO-->
<a href="http://www.bparty.org/IOS/IOS/pagevento.php?var=$idfesta[$i]">
<div style="width:90%; display:block; margin:0 auto;
padding-top:10px; margin-top:10px; padding-left:10px;
background-color:#FFF; padding-bottom:10px;
border-left:solid 8px #4D7C4F;">
<table width="100%" style=\'table-layout:fixed\'>
<tr valign="middle">
<td valign="middle" align="center" class="evntfoto"
style="background-image:url($foto[$i]);
background-position:center;
background-size: cover;">
</td>
<td valign="top" align="left" id="evnttxt">
&nbsp; &nbsp; <font color="#0066FF" size="+1"> <b> $festa[$i] </b></font> <br>
&nbsp; &nbsp; echo "$data[$i]" <br>
&nbsp; &nbsp; <font color="#585858"> $luogo[$i] </font> <br>
</td>
</tr>
</table>
</div>
</a>
<!--FINE DIV EVENTO-->
';
$i++;
}

最佳答案

您没有在循环内递增 $i。考虑改用 for 循环。另见 PHP documentationfor 循环上。

关于php - html页面中的数据库mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28916514/

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