Jump to content

How Can I... PHP and MySQL Question


maxudaskin

Recommended Posts

How would I go around getting information from a database and comparing it to some page generated information...

 

$hub = $_GET["hub"];
$rand = rand(001,999);
$pid = $hub+$rand;

 

I want it to compare $pid to information in a database and if that number is already being used, to redo the script. I know how to get it to re-do the script... I need to know how to compare to a db.

Link to comment
https://forums.phpfreaks.com/topic/59404-how-can-i-php-and-mysql-question/
Share on other sites

I mean... I don't know how to get the information to compare.

 

$hostname_LeadHost = "***";
$database_LeadHost = "***";
$username_LeadHost = "***";
$password_LeadHost = "***";
$LeadHost = mysql_pconnect($hostname_LeadHost, $username_LeadHost, $password_LeadHost) or trigger_error(mysql_error(),E_USER_ERROR);

$id = $_GET["apps"]; /* Ignore */
$hub = $_GET["hub"];
$huba = $hub/1000; /* Ignore */
function assignpid()
{
$rand = rand(001,999);
$pid = $hub+$rand;
$result = mysql_query("SELECT pid FROM `users` WHERE `pid`='{$pid}'");
}

 

What would I put in the parentheses in if() ?

Is this good?

 

Would it make sure $temppid is unique?

 

$id = $_GET["apps"];
$hub = $_GET["hub"];
$huba = $hub/1000;
$rand = rand(001,999);
$temppid = $hub+$rand;
$result = mysql_query("SELECT pid FROM `users` WHERE `pid`='{$temppid}'");
if (mysql_num_rows($result) == 1)
{
$pidcheck = 1;
}
else
{
$pidcheck = 0;
}
do
  {
  $$temppid++;
  }
while ($pidcheck==1);

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.