PHP - Mt_rand Is Producing The Same Number Instead Of Randomizing
I've used this before and it worked fine but the mt_rand is not working properly. It keeps producing the same number.
I've tested it on with the $_GET to the next page and it produces a unique code but it doesn't want to insert that number into the table, just the other same, repetitive number. $transaction_id = mt_rand() . mt_rand(); $item_email = mysql_real_escape_string($_POST[email]); $item_first_name = mysql_real_escape_string($_POST[first_name]); $item_last_name = mysql_real_escape_string($_POST[last_name]); $item_street = mysql_real_escape_string($_POST[street]); $item_street2 = mysql_real_escape_string($_POST[street_2]); $item_city = mysql_real_escape_string($_POST[city]); $item_state = mysql_real_escape_string($_POST[state]); $item_zip_code = mysql_real_escape_string($_POST[zip_code]); $item_country = mysql_real_escape_string($_POST[country]); $username = $_SESSION['username']; $item_id = $_GET['id']; $item_title = mysql_real_escape_string($_POST[title]); $item_price = mysql_real_escape_string($_POST[price]); $item_shipping_cost = mysql_real_escape_string($_POST[shipping_cost]); $item_in_shipping = mysql_real_escape_string($_POST[in_shipping]); $okay = TRUE; if ($item_country == 'United States'){ $shipping = "$item_shipping_cost"; } else { $shipping = "$item_in_shipping - <span class=\"submissionfont\">International Rate</span>"; } $sql="INSERT INTO buyer (username, email, first_name, last_name, street, street_2, city, state, zip_code, country, transaction_id, date) VALUES ('$username', '$item_email', '$item_first_name', '$item_last_name', '$item_street', '$item_street2', '$item_city', '$item_state', '$item_zip_code', '$item_country', '$transaction_id', CURDATE())"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } $sql2="UPDATE product SET transaction_id='$transaction_id', sold='1', sold_date=CURDATE() WHERE id = '$item_id'"; if (!mysql_query($sql2)) { die('Error: ' . mysql_error()); } Similar TutorialsHello Everyone,
I am working on a little project, which is basically creating a lottery draft order for our fantasy football league (I know uber cool right? lol).
I'm basically trying to mimic the old NBA draft lottery by doing something like the following:
Say our league has 12 teams and I want to weight each players chance of getting that 1st pick in the draft?
Well I would give the worst player 12 chances out of 78, 2nd to last 11 chances out of 78 etc.
So I basically created an array with values 1-78 to be my overall chances and some other arrays to assign numbers to each team member i.e. 1-12 to last place, 13-23 for send to last etc.
and I was planning to do a while loop and array_diff to narrow down the chances. here is what i have thus far:
while($x <= 12){ $num = $adjusted[mt_rand(0,count($adjusted)-1)]; Switch($num){ case in_array($num,$place12): echo $x + ' ' + 'Player12'; $adjusted = array_diff($adjusted,$place12); $x++; break; case in_array($num,$place11): echo $x + ' ' + 'Player11'; $adjusted = array_diff($adjusted,$place11); $x++; break; case in_array($num,$place10): echo $x + ' ' + 'Player10'; $adjusted = array_diff($adjusted,$place10); $x++; break; case in_array($num,$place9): echo $x + ' ' + 'Player9'; $adjusted = array_diff($adjusted,$place9); $x++; break; case in_array($num,$place8): echo $x + ' ' + 'Player8'; $adjusted = array_diff($adjusted,$place8); $x++; break; case in_array($num,$place7): echo $x + ' ' + 'Player7'; $adjusted = array_diff($adjusted,$place7); $x++; break; case in_array($num,$place6): echo $x + ' ' + 'Player6'; $adjusted = array_diff($adjusted,$place6); $x++; break; case in_array($num,$place5): echo $x + ' ' + 'Player5'; $adjusted = array_diff($adjusted,$place5); $x++; break; case in_array($num,$place4): echo $x + ' ' + 'Player4'; $adjusted = array_diff($adjusted,$place4); $x++; break; case in_array($num,$place3): echo $x + ' ' + 'Player3'; $adjusted = array_diff($adjusted,$place3); $x++; break; case in_array($num,$place2): echo $x + ' ' + 'Player2'; $adjusted = array_diff($adjusted,$place2); $x++; break; case in_array($num,$place1): echo $x + ' ' + 'Player1'; $adjusted = array_diff($adjusted,$place1); $x++; break; default: $adjusted = $lottery; break; } }Just starting out on the project so it's still pretty basic. Just trying to work on functionality right now. I am getting an undefined offset error which i assume is related to the way i'm doing and storing the mt_rand value. any thoughts on how i might fix it? Code: [Select] function choose_numbers($number,$max) { global $ibforums,$std; srand( (double)microtime() * 1000000 ); $array = array(); $i = 0; while($i!=$number) { $array[] = mt_rand(1,$max); $i++; } $c = count($array); while($c != $number) { $array[] = mt_rand(1,$max); $c = count($array); if($c == $number) { $array = array_unique($array); $c = count($array); } } return $array; } $newnumbers = $this->choose_numbers(3,36); echo "{$newnumbers['0']}|{$newnumbers['1']}|{$newnumbers['2']}"; This echo's out my lottery balls 0|32|22 or technically RANDNuMbER|RANDNUMBER|RANDNUMBER up to 36 is the highest number. Now my issue is, I don't want 2 numbers of the same Value, EVER. Sometimes it does 2|3|2 which is BAD (for my lottery system) is there anyway I can make it so it never will echo out 2 (OR 3) of the same number? Although I found a way around it, I want to know, logically, why the behavior is so. // words.txt is a text file with dictionary words on each line $lines = file('words.txt'); // The goal is to pick two random words, 10 times. for($i = 0; $i < 10; $i++) { #shuffle($lines); <--- un-commenting this is the fix i found. $words = array_rand($lines, 2); echo "Words: " . $lines[$words[0]] . ", " . $lines[$words[1]] . "<br>"; } If i don't have shuffle() in there, I get two different set of words, not 10. ie (result from code above) Words: massacre , spear Words: frontiersman , kumquat Words: massacre , spear Words: frontiersman , kumquat Words: massacre , spear Words: frontiersman , kumquat Words: massacre , spear Words: frontiersman , kumquat Words: massacre , spear Words: frontiersman , kumquat Why is this? Hi Guys I was just wondering if their is a function to randomize an array pulled from database is it possible i know their is array_rand() but it doesnt seem to work for me can someone show me where i am going wrong or do i have to do it from the actual SELECT statemant i.e ORDER_RAND(); ? Here is what my array prints out. $user_list = get_users_by_specialism($specialism); print_r($user_list); outputs. Array ( [0] => 129 [1] => 46 [2] => 57 [3] => 109 [4] => 92 [5] => 137 [6] => 238 [7] => 101 [8] => 60 [9] => 90 [10] => 112 [11] => 133 [12] => 121 [13] => 220 [14] => 275 [15] => 278 ) I basically need to make this array output in a random order everytime not by ID incrementing. Any help Please Cheers. I'm currently working on a browser based mmorpg. First things first, here is an example of my battle.php <?php include_once 'connect.php'; session_start(); include_once 'logo.php'; ?> <link href="style.css" rel="stylesheet" type="text/css" /> <div id="login2" div align="center"> <?php if (isset($_SESSION['player'])) { $player=$_SESSION['player']; } else { echo "Not Logged in <br><br> <A href='login.php'>Login</a>"; exit; } ?> </div> <?php $playerinfo="SELECT * from players where name='$player'"; $playerinfo2=mysql_query($playerinfo) or die("could not get player stats!"); $playerinfo3=mysql_fetch_array($playerinfo2); include_once 'statpanel.php'; $pid = $playerinfo3['id']; $name = $playerinfo3['name']; $playerhp = $playerinfo3['hpoints']; $playerattack = $playerinfo3['attack']; $playerdefense = $playerinfo3['defense']; if ($playerhp < 1) { echo "You are dead!" ; echo "<br><a href='inn.php>Heal at the lake"; exit; } ?> <div id="table"> <?php if (isset($_GET['randid'])) { $randid=$_GET['randid']; $iteminfo="SELECT * from inventory where randid='$randid' AND id ='$pid'"; $iteminfo2=mysql_query($iteminfo) or die("could not get item stats!"); $iteminfo3=mysql_fetch_array($iteminfo2); if (!$iteminfo3['name']) { } else { $iname = $iteminfo3['name']; $stats = $iteminfo3['stats']; $statadd = $iteminfo3['statadd']; $type = $iteminfo3['type']; if ($type == "healing") { $newhp = $statadd + $playerhp; if ($newhp > $playerinfo3['maxhp']) { $newhp = $playerinfo3['maxhp']; } $updateplayer="update players set hpoints='$newhp' where id='$pid'"; mysql_query($updateplayer) or die("Could not update player"); $updateitem="DELETE from inventory where id='$pid' AND randid='$randid' limit 1"; mysql_query($updateitem) or die("Could not delete item"); $playerhp = $newhp; echo "Used " . $iname . " and recovered " . $statadd . ".<br>"; } }} $creature = $playerinfo3['creature']; if ($creature != 0) { $creatureinfo="SELECT * from creatures where id='$creature'"; $creatureinfo2=mysql_query($creatureinfo) or die("could not get the creature you were fighting!"); $creatureinfo3=mysql_fetch_array($creatureinfo2); } else { $creatureinfo="SELECT * from creatures order by rand() limit 1"; $creatureinfo2=mysql_query($creatureinfo) or die("could get a creature!"); $creatureinfo3=mysql_fetch_array($creatureinfo2); $cid = $creatureinfo3['id']; $updateplayer="update players set creature='$cid' where name='$name'"; mysql_query($updateplayer) or die("Could not update player"); } $creature = $creatureinfo3['name']; $creaturehp = $creatureinfo3['hpoints']; $creatureattack = $creatureinfo3['attack']; $creaturedefense = $creatureinfo3['defense']; ?> </div> <div id="player"> <?php /////player info echo "<u> " . $playerinfo3['name'] . "</u><br>"; echo "Hit points = " . $playerhp . "<br>"; echo "Attack = " . $playerattack . "<br>"; echo "Defense = " . $playerdefense . "<br><br><br>"; ?> </div> <div id="creature"> <img src="images/<?php echo $creatureinfo3['imgurl'];?>" <br> <?php ///////creature info echo "<u> " . $creatureinfo3['name'] . "</u><br>"; echo "Hit points = " . $creaturehp . "<br>"; echo "Attack = " . $creatureattack . "<br>"; echo "Defense = " . $creaturedefense . "<br><br><br>"; ?> </div> <div id="options"> <?php echo "<a href='attack.php'>Attack</a>"; echo "<br><a href='usemagic.php'>Use Magic</a>"; echo "<br><a href='useitem.php'>Use Item</a>"; echo "<br><a href='index.php'>Exit Arena</a>"; ?> </div> <div id="logout"> <?php echo "<br><a href='logout.php'><img src='images/logout.gif'>"; ?> </div> Particular functions I'm interested in for zone creation. -Pay to get in & have the initial icon switch to a now usable adventure zone. (done) -When 'adventuring' in this link. Battle php randomizes encounters between 'combat encounters' and 'non-combat' encounters. (can't get this right, and removed my utter failures from the code above as to not clutter it. Pulls randomly from the Creature DB just fine but when I try to add in the 2nd,non-combat,db..it pulls nothing.) -NonCombat encounters dish our reward. (currently my non combats do not give reward. Unlike a standard creature encounter where a players gold and exper get updated on a victory...I dont know how to immediately trigger the change on encounter & I'm epically unsure how to craft the $updateplayer= to be so broad as to include all possibilities of improvement but only to utilize the one being called upon in the encounter) -I'm also interested in updating my battle.php to include a dropdown list of usable spells/items instead of the current method of Attacking/going back/selecting magic or items/going back/...repeat. It works, sure, but its nasty..Any ideas on how to call on the database for user specific data to fill in a drop down menu? I'm getting the dreaded " Invalid parameter number: number of bound variables does not match number of tokens" error and I've looked at this for days. Here is what my table looks like:
| id | int(4) | NO | PRI | NULL | auto_increment | | user_id | int(4) | NO | | NULL | | | recipient | varchar(30) | NO | | NULL | | | subject | varchar(25) | YES | | NULL | | | cc_email | varchar(30) | YES | | NULL | | | reply | varchar(20) | YES | | NULL | | | location | varchar(50) | YES | | NULL | | | stationery | varchar(40) | YES | | NULL | | | ink_color | varchar(12) | YES | | NULL | | | fontchosen | varchar(30) | YES | | NULL | | | message | varchar(500) | NO | | NULL | | | attachment | varchar(40) | YES | | NULL | | | messageDate | datetime | YES | | NULL |Here are my params: $params = array( ':user_id' => $userid, ':recipient' => $this->message_vars['recipient'], ':subject' => $this->message_vars['subject'], ':cc_email' => $this->message_vars['cc_email'], ':reply' => $this->message_vars['reply'], ':location' => $this->message_vars['location'], ':stationery' => $this->message_vars['stationery'], ':ink_color' => $this->message_vars['ink_color'], ':fontchosen' => $this->message_vars['fontchosen'], ':message' => $messageInput, ':attachment' => $this->message_vars['attachment'], ':messageDate' => $date );Here is my sql: $sql = "INSERT INTO messages (user_id,recipient, subject, cc_email, reply, location,stationery, ink_color, fontchosen, message,attachment) VALUES( $userid, :recipient, :subject, :cc_email, :reply, :location, :stationery, :ink_color, :fontchosen, $messageInput, :attachment, $date);"; And lastly, here is how I am calling it: $dbh = parent::$dbh; $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); if (empty($dbh)) return false; $stmt = $dbh->prepare($sql); $stmt->execute($params) or die(print_r($stmt->errorInfo(), true)); if (!$stmt) { print_r($dbh->errorInfo()); }I know my userid is valid and and the date is set above (I've echo'd these out to make sure). Since the id is auto_increment, I do not put that in my sql (though I've tried that too), nor in my params (tried that too). What am I missing? I feel certain it is something small, but I have spent days checking commas, semi-colons and spelling. Can anyone see what I'm doing wrong? base64_encode is a perfect standard php encoding, but this produces = most of times. Is there an alternative making the encode by alphanumeric only? I am trying to join two tables but I am producing no results. I'm convinced that I have entered everything correctly, but clearly I haven't? Can anyone spot my mistake?
<?php require 'core/memberinit.php'; $member = new Member(); include 'timeago.php'; $memberid = $member->data() ->id; if(isset($_GET['q'])) { $q = html_entity_decode($_GET['q']); $query2 = DB::getInstance()->query("SELECT c.id c.time as time, c.message as message, c.removed1, c.removed2, m1.member_first_name as firstname1, m1.member_last_name as lastname1, m1.username as username1, m2.member_first_name as firstname2, m2.member_last_name as lastname2, m2.username as username2 FROM conversation c LEFT JOIN members m1 ON c.member1=m1.id LEFT JOIN members m2 ON c.member2=m2.id WHERE (c.id=$q OR c.originalid=$q) AND ((c.member1=$memberid AND c.removed1='No') OR (c.member2=$memberid AND c.removed2='No')) ORDER BY c.id"); foreach ($query2->results() as $result2) { echo $result2->firstname1; echo $result2->lastname1; echo $result2->username1; echo timeAgo(strtotime($result2->time)); echo $result2->message; echo $result2->firstname2; echo $result2->lastname2; echo $result2->username2; } ?> Edited by MartynLearnsPHP, 23 November 2014 - 12:55 PM. Code: [Select] <?php $query = "Select * from users where username = '$user' "; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $test = $_POST['test1']; $ques = "Select * from questions where testname = '$test' "; $qres = mysql_query($ques) or die(mysql_error()); $qdetails = mysql_fetch_array($qres); $id = $qdetails['id']; $testname = $qdetails['testname']; $ans = "Select * from answers where qid = $id"; $ares = mysql_query($ans) or die(mysql_error()); if($qdetails) { ?> <div class="padding"> <form name="answerform" action="answer.php" method="POST"> <h3> </h3> <input name="test2" id="test2" type="text" value="<?php echo $qdetails['testname'];?>" /><h3><?php echo $qdetails['text'];?></h3> <input name="test3" id="test3" type="text" value="<?php echo $qdetails['testseries'];?>" /><h3><?php echo $qdetails['text'];?></h3> <br /> <br /> <br /> <?php while($opdetails = mysql_fetch_assoc($ares)) { ?> <input class="text" id="opt2" name="correctans" type="radio" value="<?php echo $opdetails['text']; ?>" /><br /><?php echo $opdetails['text']; ?> <?php }?> <div class="two-fields clearfix". <p class="confirm"> </p> </div> <input type="submit" value="SUBMIT ANSWER" /> </form> </div> </div> </div> <?php } this is the code for the program where i am creating the fields i want to fetch the data from the input fields with the name test 2 and test 3 in answer.php Code: [Select] $query = "Select score from users where username = '$user' "; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $user_score = $row['score']; print_r($_REQUEST); $tester = $_POST['test3']; $test = $_POST['test2']; print_r($_POST); var_dump($_POST); $ques = "Select * from questions where testname = '$test' And testseries = '$tester' "; $result = mysql_query($ques) or die(mysql_error()); $row = mysql_fetch_array($result); $qid = $row['id']; $score = $row['score']; if(isset($_POST['correctans'])) { $answer = $_POST['correctans']; } else { $answer = ''; } $fetch_ans = "Select * from answers where correct = 1 AND qid = $qid"; $result = mysql_query($fetch_ans) or die(mysql_error()); $row = mysql_fetch_array($result); $id = $row['id']; $correctans = $row['text']; if('$correctans' == '$answer') { $user_score += $score; $qid++; $query = "Update users set score = $user_score where username = '$user'"; $res = mysql_query($query) or die(mysql_error()); if($res) { header("Location: answer.php"); } }else { header("Location: answer.php"); } ?> THIS IS answer.php and here i try to post information from test2 and test3 fields but i am not getting any output the output shows blank array() and unidentified index test2 and unidentified index test3 i am not able to figure out the error any help will be highly appreciated and forgive me if i have made any mistakes in posting the question since i am a newbie at PHPFREAKS I am trying to produce a thresholded image with only an rgb value of zero or 255. As you can see, although I only output 0 and 255, I am finding that if I output as jpg file, I get other values in there as well. If I output as gif, I also get other values in there too. I am sure I am doing something stupid as there must be a way to do this. My test file is this attached jpg greyscale file. Is there a way to process this test file so that only 0 or 255 appears in the output image please? Thanks. Here is my program <?php $url = 'greyscale_image.jpg'; $outfile = 'greyscaleout'; $src = imagecreatefromjpeg($url); $w = imagesx($src);$h = imagesy($src); $loband = 80;$hiband = 255; $im_r = imagecreatetruecolor($w,$h); imagefill($im_r,0,0,imagecolorallocate($im_r,255,0,0)); $im_j = imagecreatetruecolor($w,$h); imagefill($im_j,0,0,imagecolorallocate($im_j,255,0,0)); for ($x=0;$x<$w;$x++) { for ($y=0;$y<$h;$y++) { $idx = imagecolorat($src,$x,$y); $rgb = imagecolorsforindex($src,$idx); // this is safest (for gifs) rather than some calculation - apparently $r =$rgb['red']; $g = $rgb['green']; $b = $rgb['blue']; $gryout = $r; if ($r <= $loband) { $gryout = 0; // everything less than= loband is black } if ($r > $loband) { $gryout = 255; // everything else is white } if ( ($gryout == 0) || ($gryout == 255) ) { // only zero or 255 allowed $idx = imagecolorallocate($im_r,$gryout,$gryout,$gryout); imagesetpixel($im_r,$x,$y,$idx); // imagesetpixel($im_j,$x,$y,$idx); // $idx2 = imagecolorat($im_r,$x,$y);// if ($idx != $idx2) { die($idx2." at x,y ".$x.",".$y); } $rgb = imagecolorsforindex($im_r,$idx); // this is safest (for gifs) rather than some calculation - apparently $r =$rgb['red']; $g = $rgb['green']; $b = $rgb['blue']; if ($r != 0) { if ($r != 255) { die($r." at x,y ".$x.",".$y); } } } else { die('<br>Grey going out to image is '.$gryout); } } } imagegif($im_r,$outfile.'.gif');imagedestroy($im_r); imagejpeg($im_j,$outfile.'.jpg');imagedestroy($im_j); // ========================== // done the writing, now check it // ========================== // $outfile = 'greyscale_image'; // test using original $src = imagecreatefromjpeg($outfile.'.jpg'); $w = imagesx($src);$h = imagesy($src); $errcount = 0; $x = 0; while($x<$w) { $y = 0; while($y<$h) { $idx = imagecolorat($src,$x,$y);// $rgb = imagecolorsforindex($src,$idx); // this is safest (for gifs) rather than some calculation $r =$rgb['red']; $g = $rgb['green']; $b = $rgb['blue']; if ($r != 0) { if ($r != 255) { echo sprintf('<br>r(%d,%d) r=%d g=%d b=%d',$x,$y,$r,$g,$b);$errcount++; } } if ($g != 0) { if ($g != 255) { echo sprintf('<br>g(%d,%d) r=%d g=%d b=%d',$x,$y,$r,$g,$b);$errcount++; } } if ($b != 0) { if ($b != 255) { echo sprintf('<br>b(%d,%d) r=%d g=%d b=%d',$x,$y,$r,$g,$b);$errcount++; } } if ($errcount > 10) {break 2;} $y++; } $x++; } if ($errcount == 0) {die( ' Checked OK' );} die( ' Checked NOT OK' ); // ================= ?> Hello,
I have problem durring binding update query. I can't find what is causing problem.
public function Update(Entry $e) { try { $query = "update entry set string = $e->string,delimiter=$e->delimiter where entryid= $e->id"; $stmt = $this->db->mysqli->prepare($query); $stmt->bind_param('ssi',$e->string,$e->delimiter,$e->id); $stmt->close(); } catch(Exception $ex) { print 'Error: ' .$ex->getMessage(); } }When I run function update I'm getting next error:Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement Can you help me to solve this problem ? Edited by danchi, 17 October 2014 - 10:25 AM. I need to display a number(the number is retrieved from the db) in the form input field such that only the last 4 digits is visbile, the remaining can be masked as * or X or whatever is applicable. I know the last 4 can be obtained as follows: Code: [Select] $number=substr($number,-4,4); But when i hit the submit button the form validates the input field and checks if the number is a valid number of a specific format. Therefore when I click on the submit button then I should still be able to unmask the masked numbers or do something similar that would help me validate the whole number. Code: [Select] <input type="text" name="no" value="<?php if(!empty($number)){ echo $number;} ?>"> I have written code so that when something from a MySQL field equals 0, then PHP will take no action, and if the field equals anything else, then 'echo "foo"'. The problem I am having is that when PHP echo's nothing (echo ""), its still creating the effect of a HTML <BR>. Screen shots: 1. When the MySQL table contains something else than 0 (echo "foo"). http://i51.tinypic.com/2n7oxo1.png 2. When the table contains 0 (echo ""). http://i53.tinypic.com/2h5jg4k.png 3. What it should look like if the table were to contain 0 (echo ""). Note that their is no <BR> effect. http://i51.tinypic.com/2jdtaf.png Code: $query = "select sizes from products where id='$id'"; $result = mysql_query($query); $data = mysql_fetch_array($result); if ($data['sizes'] == 0) {echo "";} else {echo "Small - ".$data['sizes'];} Is it possible to make it so if a MySQL field result equals 0, then PHP will not produce the HTML <BR> effect when it echo's nothing (echo "")? Hey I have a string that looks like the following: Quote top-php-tutorials-2.html I have a script that cycles through each page. The 2 in the quote above is the page number. How can I extract the number between the - and the .html and replace it with another number? I've tried Code: [Select] substr($engine->selectedcaturl, 0,-6).$v.".html"But then I realised this only works for numbers that are 1 digit long Any input would be appreciated hello, i have a start time and an end time (no dates). the following works great, except for when the start time is at night, and the end time is in the morning. im thinking if i can do an if the number is negative, add 24, that it will resolve my issue. any ideas? Code: [Select] $tbilled = $tfinish - $tstart; I am trying to create a registration form where users put their name, email and password only.
but i want to write an auto generated account number into database table for each user e.g; XY1234567 where XY should not change 1234567 auto generated random number and no duplicates (in numbers only).
example...
XY1234567
XY2345678
XY2233455
i found code
$num_of_ids = 10000; //Number of "ids" to generate. $i = 0; //Loop counter. $n = 0; //"id" number piece. $l = "AAA"; //"id" letter piece. while ($i <= $num_of_ids) { $id = $l . sprintf("%04d", $n); //Create "id". Sprintf pads the number to make it 4 digits. echo $id . "<br>"; //Print out the id. if ($n == 9999) { //Once the number reaches 9999, increase the letter by one and reset number to 0. $n = 0; $l++; } $i++; $n++; //Letters can be incremented the same as numbers. Adding 1 to "AAA" prints out "AAB". }but its not working as i want. Any help please? Edited by 684425, 27 December 2014 - 12:58 PM. hi guy's i have on one page select from table, and i don't know how to limit showing content from database on 3, and rest to make number under it and when i click on that number next 3 is showen? Something like on forum when you have more topics then you can show, on botom of page are showen numbers (links). Can some explain me how to do this? i put in while loop something like this Code: [Select] while ($prom = mysql_fetch_object($res) and $i<3) and now it is limited on showing first 3, my problem is showing next 3, and if there is more how to split it on 3 per page? Hi all I am trying to print a pattern shown below: 1 23 456 7891011 1213141516 17181920 212223 2425 26 Any know how to do it? I'm a bit stuck, I completed it with asterix. |