Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.