PHP - On Duplicate Sql Query
Hey guys just wondering if this piece of code is correct because i get a mysql error saying Duplicate entry '*********' for key 2 this is the code i have and table structure.
$sql = " INSERT INTO `IP_Address` VALUES(NULL,'".$ip."','".$date."','".$time."') ON DUPLICATE KEY UPDATE `date` = `".$date."`, `time` = `".$time."` "; Similar TutorialsCode: [Select] $PlayerQuery = "SELECT FirstName, SurName FROM players p, rounds m, entrants e, games t WHERE p.PlayerID = e.PlayerID AND m.GameID = '$ID' AND e.EntrantID = m.Player"; $PlayerResult = mysql_query($PlayerQuery); $PlayerRow = mysql_num_rows($PlayerResult); Can someone suggest why this returns game*the number of results. For each new game it returns an extra duplicate result. For example for 2 games: j Smith j Smith t John t John etc There are no duplicate entry's! and results should be unique. Not in a loop (positive) I'm working on a directory component and have kind of a tricky thing I need to do. The list of results pop through ajax on the left side along with it's google map number tag, and the google map pops on the right side. To make it even trickier the results are popped through a radius search by proximity. The problem is if there are multiple results with the same address you end up having all of the number tags on the map buried under the last tag with that address, plus it makes for kind of a long list. What I need to do is run a check to see if the previous result is the same address, and if yes not pop that result in a new table cell, rather stick it in a jquery drop down div so that all of the following results with the same address are stuffed in the jquery drop down in the same table cell under the first result with that address. In a perfect world all of the listings with the same addresses would be submitted in order so I could just do a check for the previous itemid's address, but of course that's not the case. I thought about running a query to grab ALL of the addresses and then check the item's address against it to see if it matches and if yes echo the jquery div instead of the <td>, but obviously that won't work because that will cause the first item with that address to be put in the div also. Plus I don't know if that's a very efficient way to go about it anyway. Here's kind of the basic thing I'm working with: Code: [Select] $query = "SELECT data_txt FROM jos_sobi2_fields_data WHERE fieldid = 76 AND itemid = $mySobi->id"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $myaddress = $row['data_txt']; } echo "<td $style>"; Any ideas? The only 2 tables relevant to what I want to do are "User" and "Scores." Basically this database holds high scores for a project I've been working on. I only want to display 10 scores, all from different users. No 2 or more scores from the same user. This is my db structure within phpmyadmin: Quote database -> table -> X / User / Score / X / X / X / X / X / X / X / X If possible I'd like to run a query where it checks for duplicate entries by the same user and only show the highest score. The current query I'm running is below: $result = mysql_query("SELECT * FROM table ORDER BY Score DESC LIMIT 0, 10"); Is this possible? I can only seem to find information regarding the INSERT IGNORE clause and that obviously won't help me as the users and scores are already in the database. Thanks. I am inserting the two records below simultaneously (one after the other), but what I want to do write the second ONLY if the first isn't a duplicate. Help? Code: [Select] //FIRST INSERT mysql_query("INSERT INTO spam (id, scm_mem_id) VALUES('', '$social_mem_id' ) ON DUPLICATE KEY UPDATE scm_mem_id=$social_mem_id") or die(mysql_error()); //SECOND INSERT mysql_query("INSERT INTO sc_messages (smg_from, smg_to, smg_subject, smg_body, smg_sent_del, smg_postdate) VALUES ('$social_mem_id','1','$subject','$body','1','$time')") or die(mysql_error()); Hi.. So im currently working on a script.. My script generates a "oid" based on timestamp. Ive made the "oid" field unique in my db, so if i do a quick refresh i get the message: Duplicate entry '1283195988' for key 'oid' Is there some way i can check if its a dublicate, and if it is + it with 1 or something? Hey folks, Sorry for being a pain in the ass. I am trying to submit data to my database via a form and when I click Submit, I get: Duplicate entry '' for key 1 I understand that it means I have a duplicate entry with the ID of 1 or something like that. I can't find where the issue is. Here is the form: <form actin="" id="settings" name="settings"> <table class="listing form" cellpadding="0" cellspacing="0"> <tr> <th class="full" colspan="2"><?php echo $lang_settings; ?></th> </tr> <tr> <th colspan="2"><?php echo $lang_settings_description; ?></th> </tr> <tr> <td><?php echo $lang_sitename; ?>: </td> <td><input type="text" name="sitename" value="<?php echo $site_name; ?>" width="172" /> <em>Site name for logo</em></td> </tr> <tr> <td><?php echo $lang_email; ?>: </td> <td><input type="text" name="email" value="<?php echo $site_email; ?>" width="172" /> <em>Your email address</em></td> </tr> <tr> <td><?php echo $lang_yourname; ?>: </td> <td><input type="text" name="name" value="<?php echo $your_name; ?>" width="172" /> <em>Your own name</em></td> </tr> <tr> <td><?php echo $lang_meta_description; ?>: </td> <td><input type="text" name="meta-description" value="<?php echo $description; ?>" width="172" /> <em>SEO</em></td> </tr> <tr> <td><?php echo $lang_keywords; ?>: </td> <td><input type="text" name="meta-keywords" value="<?php echo $keywords; ?>" width="172" /> <em>Separate with Commas</em></td> </tr> <tr> <td><input type="submit" class="button" name="submit" value="<?php echo $lang_button_savesettings; ?>"></td> </tr> </table> </form> Here is the Insert code: $insert = "INSERT INTO settings (site_name, description, keywords, email, name) VALUES ('$sitename', '$meta_description', '$meta_keywords', '$site_email', '$your_name')"; mysql_query($insert) or die(mysql_error()); Can anyone please tell me where I am going wrong here? Much appreciated. Hi, I have a function that returns the value of a array if it matches $string, but it only returns Test 1 instead of returning Test 1, Test 2. Can you someone see what I'm doing wrong? And it has to return N if nothing found. Code: Code: [Select] function fes($string){ $fes['Test 1'] = '104'; $fes['Test 2'] = '104'; return in_array($string, $fes) ? array_search($string, $fes) : 'N'; } echo fes('104'); thanks, Cyto Hi, I have a multidimentional array which looks like this : Code: [Select] array(2) { ["HOKIT100E-041"]=> array(3) { [0]=> string(26) "Honda Cr 125-250 2000-2001" [1]=> string(5) "89.99" [2]=> string(1) "1" } ["WAFAXS"]=> array(3) { [0]=> string(27) "Wulf Flite-x Helmet - Green" [1]=> string(5) "65.94" [2]=> string(1) "1" } } howver when I do a foreach on it, the 1st array is being duplicated and I have no idea why this is the code I have : Code: [Select] foreach($basketArray as $key => $value) { echo$nvpstr = $nvpstr ."<br/><br/>&L_PAYMENTREQUEST_0_NUMBER$q=".$key." <br/>&L_PAYMENTREQUEST_0_NAME$q=".$value[0]." <br/>&L_PAYMENTREQUEST_0_AMT$q=".$value[1]." <br/>&L_PAYMENTREQUEST_0_QTY$q=".$value[2]; $q++; } this is what is output : Quote &L_PAYMENTREQUEST_0_NUMBER0=HOKIT100E-041 &L_PAYMENTREQUEST_0_NAME0=Honda Cr 125-250 2000-2001 &L_PAYMENTREQUEST_0_AMT0=89.99 &L_PAYMENTREQUEST_0_QTY0=1 &L_PAYMENTREQUEST_0_NUMBER0=HOKIT100E-041 &L_PAYMENTREQUEST_0_NAME0=Honda Cr 125-250 2000-2001 &L_PAYMENTREQUEST_0_AMT0=89.99 &L_PAYMENTREQUEST_0_QTY0=1 &L_PAYMENTREQUEST_0_NUMBER1=WAFAXS &L_PAYMENTREQUEST_0_NAME1=Wulf Flite-x Helmet - Green &L_PAYMENTREQUEST_0_AMT1=65.94 &L_PAYMENTREQUEST_0_QTY1=1 Have I made a schoolboy error? Thanks. Hey guys! I know, I know this problem is EVERYWHERE but i just dont understand! I have a solid knowlage of php but my SQL skills are low, so i dont know too much about Keys and stuff. But my error is: Duplicate entry '' for key 2. The thing that im working on at this section is logging in with facebook. The code that presents my error is: $sql = "SELECT * FROM users WHERE uid=".$uid; $fbid = mysql_query($sql); $num_rows = mysql_num_rows($fbid); if(mysql_num_rows($fbid) < 1) { echo "You are not logged in. "; mysql_query("INSERT INTO `users` (`uid`) VALUES ('".$uid."')") or die(mysql_error()); } else { mysql_query("UPDATE users SET logged = '1' WHERE uid=".$uid); //mysql_query("UPDATE users SET full_name = $me WHERE uid=".$uid); echo "Your Logged in "; echo $me['name']; ?> Continue to <a href="removed :)"> My Settings </a>. <? } Any help is welcome Code: [Select] foreach ($items as $product ) { echo $product; ?><input type="text" size="2" value="<?php \\display quantity here ?>" name="quantity" /><?php } $items is an array. It has multiple values, some duplicate. How do i count the duplicate values in the array and display in this foreach loop? i know array_count_values($product) but putting that in the foreach loop won't accomplish what i want. another thing. i can get the foreach loop to not display duplicates by doing this Code: [Select] foreach (array_unique($items) as $product ) { echo $product; ?><input type="text" size="2" value="<?php \\display quantity here ?>" name="quantity" /><?php } how would i accomplish both. basically i want it to display the quantity without displaying duplicate rows. aka shopping cart. Hi there, I know I'm doing something stupid, but i've tried for hours to try and figure this out and I just cant seem to figure out why tutorials i've seen seem to work yet my own code doesnt. basically i've got two functions: getAll() and get($id) inside a class, calling getAll, returns an array with one of the same record as opposed to all the records (which is my intended result). Can anyone help? thanks. Code: [Select] class Test{ protected $_db; protected $_table = "table"; protected $_friends = array(); public function __construct($db) { $this->_db = $db; } public function getAll() { $db = $this->_db; $sql = "SELECT * FROM $this->_table"; $db->query($sql); while($data = $db->fetch_array()) { $this->_friends[$data['id']] = $this->get($data['id']); } return $this->_friends; } public function get($id) { $db = $this->_db; $sql = "SELECT * FROM $this->_table WHERE id='$id'"; $db->query($sql); $data = $db->fetch_array(); return (object)$data; } } $test = new Test(new mysqlConnClass()); $arrayOfAllAsObjects = $test->getAll(); hi, i have some code that i need to update existing columns in a table, but i just cant seem to get it to work if anyone caan please help it would be appreciated. Quote // select the database mysql_select_db($database) or die ("Could not select database because ".mysql_error()); $insert = mysql_query("insert into $table values ('NULL', '".$_POST['email']."', '".$_POST['password']."', '".$_POST['name']."', '".$_POST['Gender']."', '".$_POST['Age']."', '".$_POST['Race']."', '".$_POST['SpecialtyOne']."', '".$_POST['Feet']."', '".$_POST['Weight']."', '".$_POST['Eyes']."', '".$_POST['Hair']."', '".$_POST['Strength']."', '".$_POST['Stamina']."', '".$_POST['Perception']."', '".$_POST['Agility']."', '".$_POST['Intelligence']."', '".$_POST['Tech']."', '".$_POST['Luck']."', '".$_POST['Appearance']."', '".$_POST['Background']."', '".$_POST['Weapons']."', '".$_POST['Armour']."', '".$_POST['Items']."', '".$_POST['Enhancements']."', '".$_POST['Skills']."')") or die("Could not insert data because ".mysql_error()); ?> <?php Hi.... I want to know what syntax should i used for UPDATE or ON DUPLICATE KEY. Because now, I only have syntax for insert query.,I want to add syntax for update or DUPLICATE key. here is my code: Code: [Select] <?php include 'config.php'; $currentEmpID = $_SESSION['empID']; $DATE1 = $_GET['Regfirstinput']; $DATE2 = $_GET['Regsecondinput']; $smarty->assign('DATE1', $DATE1); $smarty->assign('DATE2', $DATE2); $result = mysql_query("INSERT INTO payroll.reg_att(EMP_NO, DATE_DTR, LOGIN, LOGOUT, TotalHours) SELECT EMP_NO, DATE(LOGIN), LOGIN, LOGOUT, TIMEDIFF(LOGOUT, LOGIN) FROM attendance.employee_attendance") or die(mysql_error()); $result = mysql_query("UPDATE payroll.reg_att SET Rendered = case when time_to_sec(time(TotalHours)) <= time_to_sec('03:00:00') then sec_to_time(time_to_sec('00:00:00')) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('20:35:00') AND time_to_sec('21:35:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('05:35:00') AND time_to_sec('06:35:00') then sec_to_time(time_to_sec('08:00:00')) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('04:35:00') AND time_to_sec('05:35:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('13:35:00') AND time_to_sec('14:35:00') then sec_to_time(time_to_sec('08:00:00')) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('12:35:00') AND time_to_sec('13:35:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('21:35:00') AND time_to_sec('22:35:00') then sec_to_time(time_to_sec('08:00:00')) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('06:00:00') AND time_to_sec('07:00:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('16:00:00') AND time_to_sec('16:59:00') then sec_to_time(time_to_sec('08:00:00')) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('07:01:00') AND time_to_sec('08:00:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('17:00:00') AND time_to_sec('17:59:00') then sec_to_time(time_to_sec('08:00:00')) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('07:01:00') AND time_to_sec('08:00:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('18:00:00') AND time_to_sec('18:59:00') then sec_to_time(time_to_sec('08:00:00')) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('21:35:00') AND time_to_sec('22:35:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('05:35:00') AND time_to_sec('07:35:00') then sec_to_time(time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '08:00:00')) - (time_to_sec(LOGIN) - time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '21:35:00')))) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('13:35:00') AND time_to_sec('15:35:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('21:35:00') AND time_to_sec('22:35:00') then sec_to_time(time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '08:00:00')) - (time_to_sec(LOGIN) - time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '13:35:00')))) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('05:35:00') AND time_to_sec('07:35:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('13:35:00') AND time_to_sec('15:35:00') then sec_to_time(time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '08:00:00')) - (time_to_sec(LOGIN) - time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '05:35:00')))) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('07:00:00') AND time_to_sec('07:59:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('16:00:00') AND time_to_sec('16:59:00') then sec_to_time(time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '08:00:00')) - (time_to_sec(LOGIN) - time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '07:00:00')))) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('08:00:00') AND time_to_sec('08:59:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('16:00:00') AND time_to_sec('16:59:00') then sec_to_time(time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '08:00:00')) - (time_to_sec(LOGIN) - time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '08:00:00')))) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('08:00:00') AND time_to_sec('08:59:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('17:00:00') AND time_to_sec('17:59:00') then sec_to_time(time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '08:00:00')) - (time_to_sec(LOGIN) - time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '08:00:00')))) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('08:00:00') AND time_to_sec('08:59:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('18:00:00') AND time_to_sec('18:59:00') then sec_to_time(time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '08:00:00')) - (time_to_sec(LOGIN) - time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '08:00:00')))) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('20:35:00') AND time_to_sec('21:35:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('03:35:00') AND time_to_sec('05:35:00') then sec_to_time(time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '08:00:00')) + (time_to_sec(LOGOUT) - time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '05:35:00')))) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('12:35:00') AND time_to_sec('13:35:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('18:01:00') AND time_to_sec('21:35:00') then sec_to_time(time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '08:00:00')) + (time_to_sec(LOGOUT) - time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '21:35:00')))) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('04:00:00') AND time_to_sec('05:35:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('09:01:00') AND time_to_sec('13:35:00') then sec_to_time(time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '08:00:00')) + (time_to_sec(LOGOUT) - time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '13:35:00')))) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('06:00:00') AND time_to_sec('07:00:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('13:01:00') AND time_to_sec('16:00:00') then sec_to_time(time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '08:00:00')) + (time_to_sec(LOGOUT) - time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '16:00:00')))) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('07:01:00') AND time_to_sec('08:00:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('13:01:00') AND time_to_sec('16:00:00') then sec_to_time(time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '08:00:00')) + (time_to_sec(LOGOUT) - time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '16:00:00')))) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('07:01:00') AND time_to_sec('08:00:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('14:01:00') AND time_to_sec('17:00:00') then sec_to_time(time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '08:00:00')) + (time_to_sec(LOGOUT) - time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '17:00:00')))) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('07:01:00') AND time_to_sec('08:00:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('15:01:00') AND time_to_sec('18:00:00') then sec_to_time(time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '08:00:00')) + (time_to_sec(LOGOUT) - time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '18:00:00')))) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('21:35:00') AND time_to_sec('22:35:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('03:35:00') AND time_to_sec('05:35:00') then sec_to_time(time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '08:00:00')) + (time_to_sec(LOGOUT) - time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '05:35:00'))) + time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '08:00:00')) - (time_to_sec(LOGIN) - time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '21:35:00'))) - time_to_sec('08:00:00')) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('13:35:00') AND time_to_sec('14:35:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('18:01:00') AND time_to_sec('21:35:00') then sec_to_time(time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '08:00:00')) + (time_to_sec(LOGOUT) - time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '21:35:00'))) + time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '08:00:00')) - (time_to_sec(LOGIN) - time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '13:35:00'))) - time_to_sec('08:00:00')) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('05:35:00') AND time_to_sec('06:35:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('10:01:00') AND time_to_sec('13:35:00') then sec_to_time(time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '08:00:00')) + (time_to_sec(LOGOUT) - time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '13:35:00'))) + time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '08:00:00')) - (time_to_sec(LOGIN) - time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '05:35:00'))) - time_to_sec('08:00:00')) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('07:00:00') AND time_to_sec('07:59:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('12:01:00') AND time_to_sec('16:00:00') then sec_to_time(time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '08:00:00')) + (time_to_sec(LOGOUT) - time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '16:00:00'))) + time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '08:00:00')) - (time_to_sec(LOGIN) - time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '07:00:00'))) - time_to_sec('08:00:00')) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('08:00:00') AND time_to_sec('08:59:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('12:01:00') AND time_to_sec('16:00:00') then sec_to_time(time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '08:00:00')) + (time_to_sec(LOGOUT) - time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '16:00:00'))) + time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '08:00:00')) - (time_to_sec(LOGIN) - time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '08:00:00'))) - time_to_sec('08:00:00')) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('08:00:00') AND time_to_sec('08:59:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('12:01:00') AND time_to_sec('17:00:00') then sec_to_time(time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '08:00:00')) + (time_to_sec(LOGOUT) - time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '17:00:00'))) + time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '08:00:00')) - (time_to_sec(LOGIN) - time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '08:00:00'))) - time_to_sec('08:00:00')) when time_to_sec(time(LOGIN)) BETWEEN time_to_sec('08:00:00') AND time_to_sec('08:59:00') AND time_to_sec(time(LOGOUT)) BETWEEN time_to_sec('12:01:00') AND time_to_sec('18:00:00') then sec_to_time(time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '08:00:00')) + (time_to_sec(LOGOUT) - time_to_sec(concat(substr(LOGOUT, 1,10), ' ' , '18:00:00'))) + time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '08:00:00')) - (time_to_sec(LOGIN) - time_to_sec(concat(substr(LOGIN, 1,10), ' ' , '08:00:00'))) - time_to_sec('08:00:00')) END") or die(mysql_error()); $result = mysql_query("INSERT INTO payroll.reg_hours(EMP_NO, Hours) SELECT EMP_NO, sec_to_time(SUM(time_to_sec(Rendered))) FROM payroll.reg_att GROUP BY EMP_NO") or die(mysql_error()); $sql = "SELECT MIN(DATE(LOGIN)) AS FDATE, MAX(DATE(LOGIN)) AS LDATE FROM payroll.reg_att"; $rsDate = $conn2->Execute($sql); $FDATE = $rsDate->fields['FDATE']; $LDATE = $rsDate->fields['LDATE']; $smarty->assign('FDATE', $FDATE); $smarty->assign('LDATE', $LDATE); $smarty->display('header_att.tpl'); $smarty->display('RegAttendance.tpl'); $smarty->display('footer.tpl'); ?> Hi everyone, I need a little bit of help finishing off my code. Ive managed to get this far. Code: [Select] <?php mysql_connect("") or die ("Not Connected to MYSQL"); echo "</br>"; mysql_select_db("") or die ("Not Connected to DB"); // Database Connection stuff $partialNumber = $_POST['partialNumber']; // Post the Partial number $partialNumber = strtoupper($partialNumber); $numberSearch = mysql_query("SELECT * FROM product_option_value_description WHERE name LIKE '%$partialNumber%'") or die (mysql_error()); // Query to select the key number //Query to get product ID // $productId = "SELECT product_id FROM product_option_value_description"; //Query to get product ID // while ($keyNumber = mysql_fetch_array($numberSearch)) { $id = $keyNumber['product_id']; // Query for the images // $query = "SELECT image FROM product WHERE product_id = '$id'"; $result = mysql_query($query); $row = mysql_fetch_array($result) or die(mysql_error()); $query2 = "SELECT product_option_id FROM product_option_value WHERE product_id = '$id'"; $result2 = mysql_query($query2); $row2 = mysql_fetch_array($result2) or die(mysql_error()); $query3 = "SELECT product_option_value_id FROM product_option_value WHERE product_id = '$id'"; $result3 = mysql_query($query3); $row3 = mysql_fetch_array($result3) or die(mysql_error()); ?> <div> <br /><br /> Key Number: <? echo $keyNumber['name']; ?></a> <form action="http://www.co.uk/teststore/index.php?route=checkout/cart" method="post" enctype="multipart/form-data" id="product"> <br /> <table style="width: 100%;"> <tr> <td> Colour: <select name="option[<? echo $row2['product_option_id']; ?>]"> <option value="<? echo $row3['product_option_value_id']; ?>"></option> </select></td> </tr> </table> <div class="content"> Qty: <input type="text" name="quantity" size="3" value="1" /> <input type="hidden" name="product_id" value="<? echo $id; ?>" /> <input name="submit" type="submit" value="Add to Cart" /> </div> </form> <? echo $row3['product_option_value_id']; ?> </div> <br /> <img height="150" width="150" src='http://www.co.uk/teststore/image/<? echo $row['0']; ?>'/> <? } ?> And here is my SQL Table code. Code: [Select] product_option_value_id product_option_id product_id 599 302 49 598 302 49 589 297 42 588 297 42 So as you can probably tell, it is a search program that looks for products on a shopping cart. The products will have different option values, and the php script will grab the option values and echo them in a form to post back to the cart to add the product to the basket. The problem is that the "product_option_value_id" can have lots of different values, but my code echos only the first one it finds. So when I click the add to cart button, it will only add the first option value for the product it finds. For some reason I am having a hard time explaining this, so I hope someone can help me. Thanks for looking. Hola Everybody !! I'm putting together a web app similar to Digg and was wondering if there is a function or code example I can use to avoid users submitt the same url. For example: Right now the user can submit; 1. http://www.example.com?post01 2. http://example.com?post01 3. www.example.com?post01 I want the web app to check if the link has been submitted by the user first and look for duplicate submission. Any ideas ? Thank you, V. When I move threads on my forum, I want there to be a old thread in the section it was moved from saying "Moved: new link". To do this, I'm inserting a new thread in the database with the value moved equal to the new location, so when threads are being displayed users can see the thread in the new section. Is there a quick function in MySQL that will allow me to create a duplicate row in MySQL, and then just run a quick update statement? I don't want to have to insert a whole new thread like this (unless it's the only way): //insert new thread mysql_query("INSERT INTO `threads` VALUES (null, '$id','$title', '$content', '". getUsername() ."', NOW(), '". qfc() ."', NOW(), '". getUsername() ."', '','{$_SERVER['REMOTE_ADDR']}', '0', '0', '0', '', '0')"); I have a contact form, and I want to make sure it doesn't send a bunch of duplicates if the page is refreshed after being submitted. Simple way is to make sure this record isn't identical to the one before it: select * from `contacts` where `Name`='$name' and `Phone`='$phone' and `Message`='$message' and `Subject`='$subject' and `Email`='$email' But, that checks against all records. While not likely, this could cause problems, if the same customer came back a month later and put in the same exact contact. Any way I can check it only against the very last record in the database? Something like: and `id`=XX , where XX is one less than the current auto inc id? What exactly does the entry in the title mean? I cannot make sense out of it. I would appreciate if somebody can shed some light in. The error message occurs when I try to vote with the voting system I created. I have a sorting functionality, the code is he <?php $select_category = $_REQUEST['sort_category']; $sort_date_var = $_REQUEST['sort_date']; $sort_submit = $_POST['sortSubmit']; // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (($select_category == 'All') || (!isset($select_category)) && (!isset($sort_date_var))) { // Retrieve the chosen category from MySQL $query = "SELECT * FROM con"; $data = mysqli_query($dbc, $query); //Loop through the array of data while ($row = mysqli_fetch_array($data)) { echo "<table class='knuffixTable'>"; // Display the score data echo "<tr><td class='knuffix_name'>"; echo "<strong>" . htmlentities($row['name']) . "</strong><br /></td></tr>"; echo "<tr><td class='knuffix_contribution'><pre>" . $row['contribution'] . "</pre><br /></td></tr>"; echo "<tr><td class='knuffix_categoryDate'>" . $row['category'] . " | " . date('M d, Y', strtotime($row['contributed_date'])) . " </td></tr>"; echo "</table>"; } mysqli_close($dbc); } elseif (isset($select_category) && !isset($sort_date_var)) { // Retrieve the chosen category from MySQL $query = "SELECT * FROM con WHERE category = '$select_category'"; $data = mysqli_query($dbc, $query) or die (mysqli_error($dbc)); //Loop through the array of data while ($row = mysqli_fetch_array($data)) { echo "<table class='knuffixTable'>"; // Display the score data echo "<tr><td class='knuffix_name'>"; echo "<strong>" . htmlentities($row['name']) . "</strong><br /></td></tr>"; echo "<tr><td class='knuffix_contribution'><pre>" . $row['contribution'] . "</pre><br /></td></tr>"; echo "<tr><td class='knuffix_categoryDate'>" . htmlentities($row['category']) . " | " . date('M d, Y', strtotime($row['contributed_date'])) . " </td></tr>"; echo "</table>"; } mysqli_close($dbc); } elseif (!isset($select_category) && isset($sort_date_var)) { // Retrieve the chosen category from MySQL $query = "SELECT * FROM con ORDER BY contributed_date $sort_date_var"; $data = mysqli_query($dbc, $query) or die (mysqli_error($dbc)); //Loop through the array of data while ($row = mysqli_fetch_array($data)) { echo "<table class='knuffixTable'>"; // Display the score data echo "<tr><td class='knuffix_name'>"; echo "<strong>" . htmlentities($row['name']) . "</strong><br /></td></tr>"; echo "<tr><td class='knuffix_contribution'><pre>" . $row['contribution'] . "</pre><br /></td></tr>"; echo "<tr><td class='knuffix_categoryDate'>" . htmlentities($row['category']) . " | " . date('M d, Y', strtotime($row['contributed_date'])) . " </td></tr>"; echo "</table>"; } mysqli_close($dbc); } elseif (isset($select_category) && isset($sort_date_var)) { // Retrieve the chosen category from MySQL $query = "SELECT * FROM con WHERE category = '$select_category' ORDER BY contributed_date $sort_date_var"; $data = mysqli_query($dbc, $query) or die (mysqli_error($dbc)); //Loop through the array of data while ($row = mysqli_fetch_array($data)) { echo "<table class='knuffixTable'>"; // Display the score data echo "<tr><td class='knuffix_name'>"; echo "<strong>" . htmlentities($row['name']) . "</strong><br /></td></tr>"; echo "<tr><td class='knuffix_contribution'><pre>" . $row['contribution'] . "</pre><br /></td></tr>"; echo "<tr><td class='knuffix_categoryDate'>" . htmlentities($row['category']) . " | " . date('M d, Y', strtotime($row['contributed_date'])) . " </td></tr>"; echo "</table>"; } mysqli_close($dbc); } ?> With this code I'm able to: - showcase every category by DEFAULT when someone comes to the page. - sort only by category, - sort only by date, - sort by category AND date, The problem is as you can see I have a lot of duplicate code, if I for example want to change the table that is being printed out, I have to change it on all of them. I'd like to ask how I could avoid this duplicate code. Can I for example just have the table ONE TIME at a separate place and then insert the REFERENCE _after_ the query in each if statement? Like this: if (($select_category == 'All') || (!isset($select_category)) && (!isset($sort_date_var))) { // Retrieve the chosen category from MySQL $query = "SELECT * FROM con"; $data = mysqli_query($dbc, $query); table_here(); } elseif (isset($select_category) && !isset($sort_date_var)) { // Retrieve the chosen category from MySQL $query = "SELECT * FROM con WHERE category = '$select_category'"; $data = mysqli_query($dbc, $query) or die (mysqli_error($dbc)); table_here(); } I'm just coding since 2 month so I don't know how do it, maybe I can do it with functions? I've tried doing it with functions, but I got an error since the function doesn't contain any query statement and only the table because it was trying to fetch. it looked like this: function table_here () { //Loop through the array of data while ($row = mysqli_fetch_array($data)) { echo "<table class='knuffixTable'>"; // Display the score data echo "<tr><td class='knuffix_name'>"; echo "<strong>" . htmlentities($row['name']) . "</strong><br /></td></tr>"; echo "<tr><td class='knuffix_contribution'><pre>" . $row['contribution'] . "</pre><br /></td></tr>"; echo "<tr><td class='knuffix_categoryDate'>" . $row['category'] . " | " . date('M d, Y', strtotime($row['contributed_date'])) . " </td></tr>"; echo "</table>"; } mysqli_close($dbc); } hello,
Could any body share the script for find the duplicate and delete them.
|