Jump to content

updating multiple rows with different values


takn25

Recommended Posts

Hi, I have a row called code in mysql data base now what I want to do is something like this

 

$rand=rand(1111,9999);

 

$code=mysql_query("UPDATE member SET code='$rand' WHERE clan_id='1'");

 

At the moment its updating the code row with the same random number. What I want to achieve is a unique number for each member.

 

For instance

 

Currently if the $rand=1289 lets suppose

 

Every code row will become 1289  I want the code rows to be different to each other. I tried a few things up my sleeve but no luck. How can i do this? thanks any help much appreciated.

How about adding a md5 along with the random number in a larger range.

 

A simple example

<?php
$member = $_POST['member'];

if(!isset($_POST['member']) || $member == ''){
echo "Insert a member name";
} else {
$rand_number = rand(1111,50000);
$merge_code = md5("$member$rand_number");
echo $merge_code;
}
?>
<html>
<body>

<form action="" method="post">
Member: <input type="text" name="member" />
<input type="submit" name="Make Code"/>
</form>

</body>
</html> 

 

 

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.