简体   繁体   中英

Database mysql in html page

i'm trying to put my php code that connects to my MySQL database directly in my HTML page, but something goes wrong when i try to see the page.. how can i solve the error "Fatal error: Maximum execution time of 30 seconds exceeded in /membri/bestparty/IOS/IOS/eventi.php on line 41"

if i try to remove one variable for example $festa[$i] the error persists.

<!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>

--EDIT--

Ok, i solved this, but now.. why the html page shows me the variable as "$festa[$i]" and not for example "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++;
}

You are not incrementing $i inside your loop. Consider using a for loop instead. See also the PHP documentation on for loops.

Ok, i solved this, but now.. why the html page shows me the variable as "$festa[$i]" and not for example "Lorem ipsum" ?

You should use double quotes instead of single if you want a variable in the string to get printed. But in your case you'd have to escape all double quotes in your string this way \\". The better way is instead of doing that, just to concatenate the string like this:

echo '...<b>' . $festa[$i] . '</b>...';

Do that with all variables you're echoing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM