0

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++;
}
1
  • 1
    Please, stop using mysql_*. The extension has been deprecated for some time now. Switch to mysqli or ` PDO` instead. Also: don't mix DB code with markup, that's just bad practice. As is the use of the @ operator of death. If a function generates a warning/error/notice: FIX IT, don't hush it up Commented Mar 7, 2015 at 15:36

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Edited, can you help me with the last problem now?
I got to go, just a short reply: You need double quotes (") instead of single quotes (') if you want to substitute variables inside, and use curly braces like this: "foo ${array[4]} bar"
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.