473,394 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to detect duplicate values in session array php?

im creating a student subject reservation that will add subject from a table row.I would like to detect the presence of duplicate values,then echo if the values are detected.

For example this is the click event:
Expand|Select|Wrap|Line Numbers
  1. $i=0;
  2. $b =1;
  3. while($row=mysql_fetch_assoc($sql) ){
  4.  
  5.  
  6. echo "<tr><td>".$row['Subject']."<input type='hidden' name='subj[$i]' value=".$row['Subject']."></td>
  7. <td>".$row['Lec']."<br/>".$row['Lab']."<input type='hidden' name='leclab[$i]' value=".$row['Lec']."><input type='hidden' name='lab[$i]' value=".$row['Lab']."></td>
  8.  
  9. <td>".$row['Descriptive']."<input type='hidden' name='desc[$i]' value=".$row['Descriptive']."></td>
  10. <td>".$row['Day']."<br/>".$row['Labday']."<input type='hidden' name='daylabday[$i]' value=".$row['Day']."><input type='hidden' name='labday[$i]' value=".$row['Labday']."></td>
  11.  
  12. <td>".$row['LecTime']."<br/>".$row['LabTime']."<input type='hidden' name='lectlabt[$i]' value=".$row['LecTime']."><input type='hidden' name='labtime[$i]' value=".$row['LabTime']."></td>
  13.  
  14. <td>".$row['Room']."<br/>".$row['Labroom']."<input type='hidden' name='roomlabroom[$i]' value=".$row['Room']."><input type='hidden' name='labroom[$i]' value=".$row['Labroom']."></td>
  15.  
  16. <td><input id='send' name='reserv[$i]' type='submit' value='Add' onclick='addRow('myTable')' /> </td></tr>";
  17.  
  18. $i++;
  19.  
  20.  
  21. }
  22. }
  23.  
and this is the code for the displaying in the table row

Expand|Select|Wrap|Line Numbers
  1. $c=0;
  2.  
  3.         while($c<=$counter){
  4.             if($_SESSION["S['$c']"]==""){
  5.             echo "-";
  6.             }
  7.         $array1=array($_SESSION["lect['$c']"],$_SESSION["labt['$c']"],$_SESSION["Day['$c']"] ,$_SESSION["lday['$c']"]);
  8.         if(count(array_unique($array1))<count($array1)){
  9.             echo "Duplicate entry found in array";
  10.         }
  11.         else{
  12.                     echo "<tr><td>".$_SESSION["S['$c']"] . " </td>
  13.                 <td>".$_SESSION["lec['$c']"] . "<br/>".$_SESSION["lab['$c']"] . "</td>
  14.                 <td>".$_SESSION["lect['$c']"] . "<br/>".$_SESSION["labt['$c']"] . "</td>
  15.                 <td>".$_SESSION["Day['$c']"] . "<br/>".$_SESSION["lday['$c']"] . "</td>
  16.                 <td>".$_SESSION["room['$c']"] . "<br/>".$_SESSION["lroom['$c']"] . "</td></tr><br>";
  17.              $unit=$_SESSION["lec['$c']"] + $_SESSION["lab['$c']"];
  18.                $units= $units+$unit;
  19.         }
  20.  
the problem is how to detect if i add duplicate value
sorry for my bad English.
thanks in advance
Attached Images
File Type: jpg waaaaa.jpg (26.0 KB, 212 views)
Oct 21 '11 #1
1 2716
Dormilich
8,658 Expert Mod 8TB
it depends on the definition of "duplicate value" and if you need them. to prevent having two (or more) identical SQL results, simply use SELECT DISTINCT … FROM ….

arrays can be treated similarly by applying array_unique().
Oct 24 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: NiQ | last post by:
Hello every one, this is about an array of string and may be have done several time before but i need it and wasnt able to find it so here is the problem i have an array of strings with contains...
3
by: NCZIMM | last post by:
I am trying to create a session array then use the array in a foreach. I get an error saying: "foreach statement cannot operate on variables of type 'object' because 'object' does not contain a...
6
by: John Blair | last post by:
Hi, I would like to be able to detect when a session ends in a page_load event in asp.net - is this possible? Thanks.
1
by: JTreefrog | last post by:
Hello - I've read a ton of stuff about deleting duplicate values in an array. They are all very useful - they just haven't addressed an array of objects. Here's my array: var sDat = ; The...
7
by: intscript | last post by:
Hello Everbody, Please help me to catch the duplicate values. here is my script function catchDuplicate() { with(document.form) { for (i=0; i < 26; i++)
10
chandru8
by: chandru8 | last post by:
hi to all iam using vb6.0 can any one tell me how to duplicate values in a array if possible i want to delete the duplicate values its urgent thanks
3
chandru8
by: chandru8 | last post by:
hi to all i had an array with duplicate values like a(1) = "A" a(2) ="B" a(3) = "C" a(4) = "A" a(5) = "A" A value has been repeated so that i need to concateate "Dup" to that value a(1) =...
9
by: DotNetNewbie | last post by:
Hello, I need a simple hash algorithm that will detect duplicate content in my application. I want to hash not just the content, but a few other parameters also like EmployeeID and...
2
by: dawn123 | last post by:
I have a 2-d array that the user enters tress species and diameter so it looks something like: sm 10 rm 18 bf 12 sm10 sm10 rm18 and so on.. I need to be able to seach though my array and find...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.