Jump to content

Website locking up


gvp16

Recommended Posts

Hi all, im developing a website that assigns a random number to a user when they go on to the site  and stores it in a session( this is later used as part or a shopping cart), well every so often the site completely locks up and will not load for a good deal of time.

after a long time of waiting an error is some times produced saying

" fatal error maximum execution time of 30 seconds exceeded in (page name) on line (lineno)"

 

when checking  the line of page it refers to its blank, but the closet thing to it is an include for the random number script. this is why i thing its causeing my problem.

 

if anyone has some clue how to fix this it would be great.

this is the code i am using to get the random number :

<?

while ($_SESSION["randno1"] == "")

{

$randno=rand(1, 1000000);

$randquery="SELECT * FROM basket WHERE randid like '$randno'";

$result=mysql_query($randquery) or die ("couldnt do it!");

$numrows=mysql_num_rows($result);

 

If ($numrows==0)

 

{

 

$_SESSION["randno1"]=$randno;

 

}

 

}

 

?>

 

Link to comment
https://forums.phpfreaks.com/topic/103562-website-locking-up/
Share on other sites

Try:

<?
while (!isset($_SESSION["randno1"]))
{
$randno=rand(1, 1000000);
$randquery="SELECT * FROM basket WHERE randid like '$randno'";
$result=mysql_query($randquery) or die ("couldnt do it!");
$numrows=mysql_num_rows($result);

If ($numrows==0)

{

$_SESSION["randno1"]=$randno;

}

}

?>

 

I have a question about your code.  You query the database for results comparable to the random number, but don't you have to make an entry into the database with that random number before you query the database?

Link to comment
https://forums.phpfreaks.com/topic/103562-website-locking-up/#findComment-530291
Share on other sites

Try something like this:

<?php
while ($_SESSION["randno1"] == "")
{
     $randquery="SELECT * FROM basket ORDER BY RAND() LIMIT 1";
     $result=mysql_query($randquery) or die ("couldnt do it!");
     If (mysql_num_rows($result)==1)
     {
          $row = mysql_fetch_array($result);
          $_SESSION["randno1"]=$row['randid'];
          break;
     }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/103562-website-locking-up/#findComment-530294
Share on other sites

the idea behind it is that, it generates a number, then checks the database to see if it already exsists, if does it makes another, if it does it stores the number generated in a session.

 

if i used this :

<?php

while ($_SESSION["randno1"] == "")

{

    $randquery="SELECT * FROM basket ORDER BY RAND() LIMIT 1";

    $result=mysql_query($randquery) or die ("couldnt do it!");

    If (mysql_num_rows($result)==1)

    {

          $row = mysql_fetch_array($result);

          $_SESSION["randno1"]=$row['randid'];

          break;

    }

}

?>

 

it wouldnt generate a number for me would it?

 

Thanks for you replys guys.

Link to comment
https://forums.phpfreaks.com/topic/103562-website-locking-up/#findComment-530327
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.