PHP - Unique Id By Array_ Shift?
I want to give a unique ID for each run of my php script. I was thinking of creating an array(1,2,3,4,5...), as I can regularly take the first value and delete. Is there any command like array_ shift to do so?
array_ shift take the first item but does not permanently delete it; thus, it will be the first item again in the next run. Or do you have a subtle idea for assigning unique ID to each run? Similar TutorialsI have a mysql table which will store users email addresses (each is unique and is the primary field) and a timestamp. I have added another column called `'unique_code' (varchar(64), utf8_unicode_ci)`. What I would very much appreciate assistance with is; a) Generating a 5 digit alphanumeric code, ie: 5ABH6 b) Check all rows the 'unique_code' column to ensure it is unique, otherwise re-generate and check again c) Insert the uniquely generated 5 digit alphanumeric code into `'unique_code'` column, corresponding to the email address just entered. d) display the code on screen. What code must I put and where? **My current php is as follows:** Code: [Select] require "includes/connect.php"; $msg = ''; if($_POST['email']){ // Requested with AJAX: $ajax = ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'); try{ if(!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){ throw new Exception('Invalid Email!'); } $mysqli->query("INSERT INTO coming_soon_emails SET email='".$mysqli->real_escape_string($_POST['email'])."'"); if($mysqli->affected_rows != 1){ throw new Exception('You are already on the notification list.'); } if($ajax){ die('{"status":1}'); } $msg = "Thank you!"; } catch (Exception $e){ if($ajax){ die(json_encode(array('error'=>$e->getMessage()))); } $msg = $e->getMessage(); } } I'm creating a shift system where it stores into database which shift is the user in. However sometimes their shift extends over the other shift. How can I implement it better I'm currently using the time to get which shift they are on. There are two shift. 1) morning: 0800 - 1930hrs 2) night: 1930 - 0800hrs
Sometimes the shift will overrun. How do I maintain on which shift they were.
$whatshift = (int) date("Hi"); if ($whatshift > "0800" && $whatshift < "1800") { $shift = 1; } else { $shift = 2; }
Hello everyone, hopeing this is the correct place to place this, if not I apologize. I dont have a script, but here is what I hope to accomplish. There are 4 crew working, each works two days, then two nights then gets 4 off. Ex.. A platoon works 17th day, 18th day 19th night, 20th night then gets 4 off B platoon works 19th day, 20th day, 21st night, 22nd nght then gets 4 off C platoon works 21st day, 22nd day, 23rd night, 24th night then gets 4 off D platoon works 23rd day, 24th day, 25th night, 26th night then gets 4 off A platoon works 25th day, 26th day...... This schedule revolves like that for the entire year. (if A is working days, then D is working nights etc) I wanted to know if anyone could help me create a script that displays which crew is currently working, a script example that knows it is the 23rd and outputs "D platoon is on Duty" If anyone understands this and can help, please let me know. Thanks Hey everyone, im building a simple php portfolio website (header , index, footer) I have 3 pages , about , contact, portfolio If I add an image to the index page then click on my about page (no images) the whole site shifts to the right about 20px. If I remove the image and click the link everything is okay. Anyone know what im doing wrong? Code below: header Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" href="style/style.css" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="header"> <ul> <li><h2><a href="portfolio.php">PORTFOLIO</a></h2></li> <li><h2><a href="about.php">ABOUT</a></h2></li> <li><h2><a href="contact.php">WHAT WE CAN DO TOGETHER</a></h2></li> </ul> </div> index Code: [Select] <?php include 'header.php'; ?> <div id="idea_container"> <a href="portfolio.php"><img src="images/logo.jpg" width="960" height="500" /></a> </div> <?php include 'footer.php'; ?> footer Code: [Select] <div id="footer" class="footer"> <ul> <li><a href="#">TWITTER</a></li> <li><a href="contact.php">CONTACT</a></li> <li><a href="index.php">HOME</a></li> </ul> </div> </div> <!--ending div for wrapper --> </body> </html> Hello PHP freaks,
my codes dont allow me to log-in to Student Home with unique id. It says "Invalid Login or Password"
this is my form
<tr bgcolor="#E1E1E1" class="stylesmall"> <td width="35%" align="left" class="style7 style1">Learner Id : </td> <td width="65%" align="left"><input name="learner_id" type="text" id="learner_id" action="Student_Home.php" method="post"></td> </tr> <tr bgcolor="#E1E1E1" class="stylesmall"> <td align="left" class="style7 style1">Password:</td> <td align="left"><input name="student_password" type="password" id="student_password">< /td>and this is my handler. <?php session_start(); include 'Connect.php'; $flag = ""; $learner_id = $_POST['learner_id']; $student_id = $_POST['student_id']; $student_password = $_POST['student_password']; $query = "select last_login_date from student_information where student_id='$student_id' and student_password='$student_password'"; $result = mysql_query($query,$link_id); if(mysql_error() != null){ die(mysql_error()); } if($date = mysql_fetch_array($result)) { $lastdate = $date['last_login_date']; $date2 = date("d-m-Y h:i A",strtotime($lastdate)); $_SESSION["student_id"] = $_POST["student_id"]; $_SESSION["lastlogin"] =$date2; $_SESSION["type"] = "Student"; mysql_query("UPDATE student_information SET last_login_date=now() where student_id='$student_id'",$link_id); if(mysql_error() != null){ die(mysql_error()); } header("location: Student_Home.php?id={$student_id}"); die(); } else { $flag = "invalid"; header("location:Student_login.php?flag=$flag"); die(); } ?>PLease help me PHP friends to correct my codes. I am having some problems getting a query correct. Basically I have two tables, one with listings and another with categories. In the listings table I have a column called shortdescription. I am trying to pull the shortdescription from the listings table with the query $shortdesc = array_shift(mysql_fetch_row(mysql_query("select shortdescription from links where category = '".$scat->id."' "))); The shortdecription display properly on the pages display the listings, however I am getting the following error on any pages that only display the parent categories Warning: array_shift() [function.array-shift]: The argument should be an array in /home/...path/file.php on line 1462 The listings id numbers begin at 75+ because the initial parent category id ends at 74. The query seems to be searching for listing ids below 75 and spitting out an error because it is not finding them. Any ideas on how to eliminate this error and/or stop the query from looking for non-existant data? Whats the easiest way to rename uploaded files to a unique name that would never be duplicated? Hi i'm making a new website based on PHP. I bumped on a problem now... The problem is that I have a loop where i get all records out of my sql database and get them into a form. Every record has a differend form with a button to. Every button then has a unique ID. Now i tried everyting i could think of to get the value out of a button when a button is clicked. But nothing worked... here is the part of the code where everything is for the form and the POST. Code: [Select] while($record = mysql_fetch_object($result)){ $id = $record->id; echo"<form action='home.php' method='post'>"; echo"<b>name:</b>".$record->name." <b>Price: </b>".$record->price.""; echo'<input type="hidden" name="id" value='.$id.'>'; echo"<input type='submit' value='Buy' /><br />"; echo"</form>"; } if($_POST) { $ID = intval($_POST['id']); $query1 = "SELECT price FROM items WHERE id = ".$ID.""; $result1 = mysql_query($query1); list($cost) = mysql_fetch_row($result1); $gold = getStat('gc',$userID); if($gold > $cost) { setStat('gc',$userID,($gold - $cost)); $queryw = "INSERT INTO users_inventory(item_id,user_id, quantity) VALUES ('".$ID."','".$userID."','1')"; $resultw = mysql_query($queryw); } else { echo"You can't afford this weapons."; } } The only thing that doesn't seem to work is this part Code: [Select] $ID = intval($_POST['id']); is always gives me this error: Notice: Undefined index: id in shop.php on line 26 Please help me out here i have no idea what to do from here on... Howdy, The following code wil geenrate a dynamic pull-down list based on column values. Can someone help me tweak it so that is will NOT display a duplicate record value. That is, if the sponsors values in the table were Hart, Michaels, Michaels, Morella ...it would only display Hart, Michaels, Morella in the pull-down menu. <form name="form0"> <? $result = @mysql_query("select distinct sponsor from table ORDER BY sponsor ASC"); if (mysql_num_rows($result) > 0) { print "<select name=\"link\">"; ?> <option <?php if(empty($_GET['sponsor'])){ echo "selected=\"selected\""; } ?> value="<? echo "$page_name" ?>">SELECT A SPONSOR</option> <? while ($row = mysql_fetch_array($result)) { print "<option "; if($_GET['sponsor'] == $row['sponsor'] ){ echo "selected=\"selected\""; } print " value=\"index?sponsor=" . $row['sponsor'] . "\">" . $row['sponsor'] . "</option>\n"; } print "</select>"; } ?> </form> Thank you. ~Wayne i have table in my db that has rows of dates, for example... id | date | created | display | group | 1 | 2011-05-24 00:00:00 | 2011-05-24 20:00:00 | Y | 20 | 2 | 2011-05-24 00:00:00 | 2011-05-24 22:00:00 | N | 20 | 3 | 2011-05-26 00:00:00 | 2011-05-26 22:00:00 | N | 20 | 4 | 2011-05-27 00:00:00 | 2011-05-26 22:00:00 | N | 20 | 5 | 2011-05-27 00:00:00 | 2011-05-30 22:00:00 | N | 20 | Now i'm trying to make sure that each group has no duplicate dates. If they do delete all but the newest. So in this case, after the code ran, it would have deleted row 2 and row 5 because they both have duplicate dates and they're the oldest of those particular duplicates. I posted in the PHP board and not the MySQL board because it's the logic i can't figure out. I believe array_unique() would come in handy but i can't wrap my head around how to use it to do what i want. Hey everyone! My upcoming site will host, potentiallly thousands of photographs, and i was wondering how to go about having a unique ip hit counter for EACH image. Obviously i dont want people refreshing the page to gain hits, therefore the hit counter will need to be dependent on the IP address. I have used google and found a few hit counters however i need to know how to make this practical as it seems like it will require a lot of databases! Thanks in advanced, Jimmy. Need a bit of help with some php and a few kind members helped me in the past. My code is: $query = "SELECT names FROM table WHERE type='$type'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { foreach(unserialize($row['names']) as $key => $value){ echo $value . '<br />'; } } Basically, a field on my table is called names. The information in this field is serialized (so many names are together in a single field, for a single row). I want to be able to search the whole table (where type='$type' - so many rows) for all names and then show unique names only. My code above unserializes the names from each field and then lists them, but doesn't deal with any duplicates (which I need removing). I have looked at functions like "unique_array()", and have tried using it in different places but it isn't doing the job. Any help appreciated. Hi, I just need someone to check that a couple of lines I've written do what I believe them to do... i.e. check my logic! I'm developing a booking form for booking on events. Each booking needs a unique reference, which needs to be meaningless to the customer, so I am BASE36 encloding it. As the booking is be saved to a MySql database, my approach is to use the auto-incremented ID for the record to make the reference unique. The increment starts at 10000, and I add a random number before coding to make the encoded reference longer. I then BASE36 encode it to make it appear random. Am I right in thinking the reference produced WILL be unique ... provided the auto-inc ID is unique? $ref = rand(100,999) . $auto_incremented_id; //e.g. 354 & 10012 = 35410001 $ref_encoded = strtoupper(base_convert($rand, 10, 36)); // e.g.UD4J8P Thanks ok so i have an array which has duplicate values in it. i used array_unique() to remove duplicate values. the array had values 1,2,2,3. after the following code: $unique = array_unique($suggest); $size = count($unique); for ($x=0;$x<=$size;$x++) { echo $unique[$x]; echo "<br>"; } it prints out 1,2 and then gives an error, "Notice: Undefined offset: 2 in E:\wamp\www\Copy of pro2\Classes.php on line 1074" and then finally 3. any ideas how i can solve this. im assuming that array_unique() assigns the index 0,1,3 of the duplicate value array to unique array at the same indexs 0,1,3. since the index 2 of duplicate array is a duplicate value it is ommited but the unique array does not have an array at index 2. Hey guys. I need to know how to get a time that is constant. What I want to achieve: I need to make a clock on my website showing only one time (HH:MM:SS), wherever the page is requested from. And I need to use this "time" in calculations, like finding the time difference between two time values stored in my MYSQL Databases. I hope that I am clear with my question. Thanks for any help in advance! hi, im trying to create a website and only now started thinking about the security part(noob mistake). say for example i have home.php page and an index.php page. index.php is where users would sign up/log in. the login and sign up processes are all done but i was thinking of creating a unique id of some sort for when the user logs in. or something like this site (forum.phpfreaks) when we sign in, you are signed but the url stays the same = forums.phpfreaks.com. like if we were signed out we will be permanantly signed out and typing in forums.phpfreaks.com would just land us at the main page where we need to sign in.
right now ,my home.php can be accessed with or without logging in even with sessions.
hope im making sense, thanks in advanced!
**haha that rhymed.
i tried adding:
<?php echo $_SERVER[PHP_SELF] . '?name=' . $userData['name'];?> in the index.php:
<?php ob_start(); session_start(); if(isset($_POST['login'])) { $email = $_POST['email']; $password = $_POST['pass']; require "connection.php"; $emails = mysqli_real_escape_string($con, $email); $query = "SELECT id, name, email, password, salt FROM users WHERE email = '$emails';"; $result = mysqli_query($con, $query); if(mysqli_num_rows($result) == 0) // User not found. So, redirect to login_form again. { echo "<script>alert(\"User does not exist!\")</script>"; } $userData = mysqli_fetch_array($result, MYSQLI_ASSOC); $hash = hash('sha256', $userData['salt'] . hash('sha256', $password) ); if($hash != $userData['password']) { echo "<script>alert(\"Incorrect Password!\")</script>"; }else{ session_regenerate_id(); $_SESSION['sess_user_id'] = $userData['id']; $_SESSION['sess_name'] = $userData['name']; session_write_close(); header('Location: home.php?user='); } } ob_flush(); ?> <!DOCTYPE html> <form name="login" method="post" action="<?php echo $_SERVER[PHP_SELF] . '?name=' . $userData['name'];?>">but i got access forbidden! Edited by noobdood, 19 May 2014 - 10:05 PM. Hey everyone. I have been working on a cart for my site and I've reached an impasse. I coded up the cart, the add to cart, the delete from cart and the subtract from cart. Problem is I now see a need to put an image for everything that is added to the cart. I think i have devised a way to do it with frames, the left frame being the cart and the main frame is purely for the images. I am having trouble getting the code right between the two pages to work. I need a picture on the right of every item added to the cart. Here is the url for the cart: http://www.theblack44s.com/Merchant%20pages/index3.php I know this kind of thing can get extensive and I don't mean to take up any more of your time than necessary so if there are any suggestions or ideas of where I can find this information to learn it that would be just as good. Hey thanks for your time! A Hi: Not sure if this is where to ask this (maybe it's a mySQL Issue)?? I am working on a zip code locator. The field/column "zip" (which holds the zip codes) is set as a UNIQUE Key in the database. Problem is: I want to allow people to enter a new city if there is one they want to add. The only way I can do this is to remove the UNIQUE Key from the column, or I get an error. Some cities - like Malvern, PA and Frazer, PA - have the same zip code: 19355 This works fine, but the issue that now happens is the zip locator on the frontend will no longer find that zip code. Does anyone know what a solution might be? I can post the zip locator code, and maybe there's a chunk of code I can remove or alter to fix this? Not sure how to address this one. what is the easiest way to get unqiue sub arrays based on date from within my larger array? here is what i mean in detail. I have an array that outputs this... Code: [Select] [0] => Array ( [date] => 2010-11-02 [time] => 7:00 p.m. [location] => Illinois [team1] => [team1sc] => [team2] => [team2sc] => [winner] => Illinois ) [1] => Array ( [date] => 2010-11-02 [time] => 7:15 p.m. [location] => Purdue [team1] => University of Indianapolis [team1sc] => 59 [team2] => Purdue [team2sc] => 82 [winner] => Purdue ) [2] => Array ( [date] => 2010-11-06 [time] => 3:05 p.m. [location] => Southern Illinois [team1] => University of Indianapolis [team1sc] => 58 [team2] => Southern Illinois [team2sc] => 65 [winner] => Southern Illinois ) I don't need value [ 1 ] because value [ 0 ] already has the same date! My goal is to get a list of all the unique [date]s from this entire multidemonsional array. (FYI - I know I will be loosing blocks of arrays that have duplicate dates - THATS OK). But it's a bit of a struggle for me unique array sections out of this...any help or advice would be great! thanks! |