Jump to content

Eternal Loop?


EmperorJazzy

Recommended Posts

Howdy,

 

I'm utilising a random number as an ID for each new object created. At the creation stage (input to database tables), I'm wishing to check that the new random number doesn't already exist. Here is my code;

 

Field 'ListID' is a varchar field

 

		while ($listid='')
		{
			$listtest = rand(1000000000,9999999999);
			$query = "SELECT ListID FROM tblUserList WHERE ListID='" . $listtest . "'";
			$result = mysqli_query($dbc, $query) or die('Error checking ListID - ' . $query);
			$row_cnt = mysqli_num_rows($result)
			If ($row_cnt=0)
				{
				$listid=$listtest;
				}
		}

 

The code is not executing; essentially, there are no error returns and the page continues to sit idly waiting for something to return. Is this loop ot logical?

Link to comment
https://forums.phpfreaks.com/topic/232430-eternal-loop/
Share on other sites

So...

 

<?php

		while ($listid='')
		{
			$listtest = rand(1000000000,9999999999);
			$query = "SELECT ListID FROM tblUserList WHERE ListID='" . $listtest . "'";
			$result = mysqli_query($dbc, $query) or die('Error checking ListID - ' . $query);
			$row_cnt = mysqli_num_rows($result)
			If ($row_cnt==0)
				{
				$listid=$listtest;
				}
		}

?>

 

Should I also use the == for the while statement?

<?php

  while ($listid=='')

?>

Link to comment
https://forums.phpfreaks.com/topic/232430-eternal-loop/#findComment-1195609
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.