PHP - Find Duplicate Links In Mysql Table
Hi there
I'm trying to work out how I'd go about searching my database for URLs that have been submitted by users that are duplicates. Now this isn't as simple as http://www.example.com/something.php and http://www.example.com/something.php oh no! People have entered links such as http://www.example.com//something.php or http://www.example.com///something.php The script (I didn't write it) currently see's these links as unique, but they're not. They function exactly the same way. Anyone have any advice on how to weed these out? I was thinking maybe a straight forward LIKE '%//%' in the mySQL syntax, but this will bring all URLs up due to the http:// aspect of the link Any feedback would be appreciated! Similar Tutorialshello,
Could any body share the script for find the duplicate and delete them.
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')"); Hello everyone. I'd like to know how to duplicate a product through a php back-office. That product consists of an ID in the "products" table of my DB. Then we have another table called "sub_products" that links its sub-products through a column named "product_id". So I have product with ID "1000", and sub-products associated with it on another table with ID's "2021", "2022", "2023". What's the routine I can use to duplicate both the product and its sub-products? I need to duplicate them because they fit 2 categories so I'm changing the category column during this duplicate. Could really use some help. Thank you in advance! I'm learning to develop social media buttons, and I'm trying to figure out, how to find out the correct submit links to the social media sites? For example: Digg has their submit link like this: return "<a href='http://digg.com/submit?url=$link& title=$title&bodytext=$text'>Digg This</a>"; Digg also requires to use urlencode for the variables inside the URL. But delicious has their submit link like this: return "<a href='http://del.icio.us/post?url= $link&description=$text&replace=no'>Add to Delicious</a>"; When I go on delicious.com (under this URL: http://www.delicious.com/help/api#posts_add) I will find the link: Code: [Select] https://api.del.icio.us/v1/posts/add? Which is stated on the API page, but that link won't work. I rather have to use the link I showed earlier. So my question is, what is the proper way in figuring the correct submit links for each website and how to format them properly to their requirements, I can not find any information on the websites? So I can build social media buttons to the other sites as well. while ( $categories = $category_result -> fetch_assoc() ) { $menu_sql = "select * from menu where category_id = {$categories['category_id']}"; $menu_result = $handle -> query( $menu_sql ); $category2 = strtoupper($categories['category']); echo '<h3 id="' . $category2 . '">' . $category2 . '</h3>'; while ($menu = $menu_result -> fetch_assoc()) { echo $menu['item_name'] . ' '; $size_sql = "select distinct size from size where category_id = {$categories['category_id']} order by size desc"; $size_result = $handle -> query( $size_sql ); while ($size = $size_result -> fetch_row()) { echo $size[0] . ' '; } //get base type from base_type table for the pizza category $type_sql = "select type from base_type where category_id = {$categories['category_id']}"; $type_result = $handle -> query( $type_sql ); while ($type = $type_result -> fetch_row()) { echo $type[0] . ' '; } //get price for each item from menu if it is not null $price_sql = "select price from menu where item_name = '{$menu['item_name']}'"; $price_result = $handle -> query( $price_sql ); while ($price = $price_result -> fetch_row()) { echo $price[0] . ' '; if( is_null( $price[0] ) ) { //get price from size table if price is null in menu table; //$categories = $category_result -> data_seek(0); $size = "double"; $category_id = $categories['category_id']; $item_id = $menu['item_id']; $type = 'deep'; echo $menu['item_id']; $price_size_sql = "select price from size where size = '$size' and category_id = $category_id and item_id = $item_id"; $price_size_result = $handle -> query( $price_size_sql ); while ($price_size = $price_size_result -> fetch_assoc()) { echo " {$price_size['price']} "; } } } echo '<br />'; } echo '<br />'; } I get duplicate vakues for $category_id = $categories['category_id']; $item_id = $menu['item_id']; dont know whats wrong it works for pizzas but not burgers, please help me. Hello, i've got this code, to insert some form data into my db, it checks for a value if it exists already, it won't insert, now i want to add another value to check, but i don't know how. This is my code: Code: [Select] <?php if(isset($_POST['submit'])){ if (strlen($_POST['code']) == 12 && substr($_POST['code'],0,6) == '610147'){ $code = $_POST['code']; $select_query = mysql_query("SELECT * FROM jupiter WHERE code = '$code'"); if(mysql_num_rows($select_query) == 0){ $remote_addr = $_SERVER['REMOTE_ADDR']; $secret = $_POST['euro']; mysql_query("INSERT INTO jupiter(code,euro,ip,date,used) VALUES('$code','$secret','$remote_addr',CURDATE(),'n')"); } Print "<font color='green'>OK</font>"; } else { Print "<font color='red'>Error</font>"; } }?> This checks if "code" already exists, now i want to also have it check for "ip" Can someone help me out here please. Thanks ! Hello, i am inserting some form data into my mysql db, i happen to get some duplicates so i want to check first if the entry exists already before i insert. my current code: Code: [Select] <?php if(isset($_POST['submit'])) { ?> <?php if (strlen($_POST['code']) == 19 && substr($_POST['code'],0,7) == '5541258') { mysql_query("INSERT INTO table(code,secret,ip,date) VALUES('$_POST[code]','$_POST[secret]','$_SERVER[REMOTE_ADDR]',CURDATE())"); Print "<font color='green'>The code will be checked now</font>"; } else { Print "<font color='red'>The code is invalid</font>"; } ?><?php } ?> I would like to use the value 'code' to check if the entry exists, that one is unique for each entry. How would i do that ? Thanks ! 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. Is there a way to duplicate all rows in a table AND change one field's value for each new row?
For example...
TABLE: comments
FIELDS:
commentid
userid
comment
weeknumber
Say there are only 5 comments in there like this (I have MANY rows, but keeping sample size small for example's sake)...
1-17-hello-3
2-41-hey-3
3-18-yo-3
4-67-sup-3
5-12-hola-3
I would like to duplicate them AND make the "weeknumber" = 4, so the table ultimately has 10 rows like this...
1-17-hello-3
2-41-hey-3
3-18-yo-3
4-67-sup-3
5-12-hola-3
1-17-hello-4
2-41-hey-4
3-18-yo-4
4-67-sup-4
5-12-hola-4
Is this doable?
Thanks...
[ Newbie Alert ] Hi i have an array of 39 arrays. Only 5 are shown below so that you have an idea before i ask my question. <? array(39) { [0]=> array(3) { [0]=> string(18) "unit name 1" [1]=> string(9) "category name 1" [2]=> string(20) "Course 1" } [1]=> array(3) { [0]=> string(54) "unit name 2" [1]=> string(15) "category name 2" [2]=> string(20) "Course 1" } [2]=> array(3) { [0]=> string(29) "unit name 3" [1]=> string(15) "category name 2" [2]=> string(20) "Course 1" } [3]=> array(3) { [0]=> string(64) "unit name 4" [1]=> string(30) "category name 3" [2]=> string(20) "Course 2" } [4]=> array(3) { [0]=> string(57) "unit name 5" [1]=> string(24) "category name 1" [2]=> string(20) "Course 1" } [5]=> array(3) { [0]=> string(50) "unit name 6" [1]=> string(24) "category name 4" [2]=> string(20) "Course 2" } } i want a php solution to print category names in table headers , unit names in table rows and course name(s) in table caption.I have tried foreach loop but how to remove duplicate entries as you can see category name 1 and 2 will become two separate headers instead of one and same is the case with Course 1 and 2. i have googled but could'nt find any solution. i don't want to remove duplicate entries , all i want to display them once in a table as described above. Ultimate goal is for the query to find the row in the database to avoid the validation and carry on with the rest of the script. What actually happens is the script runs without any parse errors but it doesn't find the row within mysql. $query = sprintf('SELECT name_id, title, description, price, width, height, depth, quantity FROM art WHERE product_code = "$u"', mysql_real_escape_string($product_code, $db)); $result = mysql_query($query, $db)or die(mysql_error($db)); if (mysql_num_rows($result) != 1) { header('Location: home.php'); mysql_free_result($result); mysql_close($db); exit(); } I've echoed the where variable and the mysql_num_rows($result). the where variable is as expected but the result variable comes out as 0. I've checked my phpadmin and there is a entry in there. This worked fine before I sprinted the table. Any help appreciated. Hello, I want to know which is the table in the sql SELECT query. What i have done to take fields : Code: [Select] $temp_sql = strtolower($sql); $pos = stripos($temp_sql, 'select'); $str = substr($temp_sql, $pos); $str_two = substr($str, strlen($start)); $second_pos = stripos($str_two, 'where'); $temp_fields = substr($str_two, 0, $second_pos); $fields = trim($temp_fields); But for table i don't know what to do. After the table can end the string or can be a WHERE or ORDER . Is there any way to take it. Until now i use $temp = explode(' ',$sql); $table= $temp[3]; Thank you This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=312600.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=343372.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=350064.0 Hi guys I am new here I have had a search around and can't really find out how to do this. Its quite difficult for me to explain and I am really new to PHP / mySQL - just starting out really. I hope to learn from doing small projects like this and seeing how it gets done. So I have a mySQL DB with two different tables - one is called "notesnew" the other is called "users". I have modified a common tutorial on how to make a "to do list" for what I am doing here. Basically users can login and post messages on this list as them self. Each user's post appears as a list item, showing their username, the time they posted the message and the message content. The message content, time and owner of the message is stored in the "notesnew" table. The list of user's, their passwords and their "avatar/profile" image URL location is stored in the "users" table. Now I am having trouble getting each user's avatar image from being output next to each of their posts. The part that is confusing me is being able to match up the username's post with their content that is display - because I am posting the user's name along with their post, based on the logged in "session name" as their username. So basically, all the content being listed is being displayed from the "notesnew" table. I need to somehow figure out what each user's profile image is based on what is stored against their entry in the "users" table. Here is the code I have so far. It is not working properly - it displays all content etc, but displays the avatar / image of the last user that has registered. Can anyone help me out here with some code that works, or pointers to try follow? I know the $finduserprofile part is incorrect in the way it goes through all user's and finds their profileimg, and that the image displayed next to each post is therefore incorrect (as it displays the last member to have registered's avatar, but its just that I don't know how else to do what I am trying to do. Code: [Select] <?php //Connect to the database $connection = mysql_connect('localhost', 'zzzz' , 'zzzzzzz'); $selection = mysql_select_db('zzzzz', $connection); $username = $_COOKIE['ID_my_site']; //Was the form submitted? if($_POST['submit']){ //Map the content that was sent by the form a variable. Not necessary but it keeps things tidy. $content = $_POST['content']; //Insert the content into database $ins = mysql_query("INSERT INTO `notesnew` (content, owner, dp_time) VALUES ('$content', '$username', NOW())"); //Redirect the user back to the members or index page header("Location:index.php"); } /*Doesn't matter if the form has been posted or not, show the latest posts*/ //Find all the notes in the database and order them in a descending order (latest post first). $find = mysql_query("SELECT * FROM `notesnew` ORDER BY id DESC"); $finduserprofile = mysql_query("SELECT * FROM `users` ORDER BY id DESC"); //Setup the un-ordered list echo '<ul>'; while($row = mysql_fetch_array($finduserprofile)) { $imagelocation = $row['profileimg']; //Continue looping through all of them while($row = mysql_fetch_array($find)) { $owner = $row['owner']; //For each one, echo a list item giving a link to the delete page with it's id. echo '<li>' . '<img src ="' . $imagelocation . '">' . $row['owner'] . ' said at ' . $row['dp_time'] . ': ' . $row['content'] . ' <a id="' . $row['id'] . '" href="delete.php?id=' . $row['id'] . '"><img src="delete.png" alt="Delete?" /></a></li>'; } } //End the un-ordered list echo '</ul>'; ?> okay I am using a jquery plugin to re-arrange images which are in mysql and they have their own "order_number" ... when i re-arrange stuff the new order is put into a hidden field in a form and i have it along with another hidden field with their current order... when submitted I combine these two fields in an array so the key is the original order and the value is the new order ....i have 12 images... Array ( [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 [10] => 10 [11] => 11 [12] => 12 ) this is what is what the array looks like... i have a foreach loop with a mysql query but things get kind of weird when you try to do it this way $num = $_POST['old_num']; $num = unserialize($num); $sort = $_POST['sortOrder']; $sort = explode(',', $sort); if ($_POST){ $combine = array_combine($num, $sort); foreach($combine as $key => $value){ mysql_query("UPDATE shirts SET order_number='$value' WHERE order_number='$key' ") or die(mysql_error()); } when you do this lets say for example we have the image with order number "1" get switched with the image order number "2"..... the database first updates with number 1 which becomes 2... then when it goes to number "2"... at this point... the first image gets switched back to number 1.... so 1 becomes 2 then the new 2 becomes 1 again and the other 2 becomes 1 also. I can not think of another way I could update mysql with the correct order numbers... If anyone has any ideas or other solutions I am open to all suggestions... thank you! I have a payment button for PayPal which securely stores the amount, but when the payment is made how do i know if it was paid or not so i can get the page to store this in the mysql database? Dear all, I would like to find the total number of individual record in MySQL with php. For example: I have different department name stored in a column in MySQL. I would like to find out the total number of each department. But I do not know the names of the department How can I do it?? Counting the total of each department without knowing their names Thanks! Ok basically I'm working on a members page and I want the member's username to link to their profile. I've tried a couple of different things, none of which work. It's been a long time since I've done this type of thing so I can't remember how to do it. I also only want the row names (name, timezone, server, etc) to show ONCE instead of above every member's info. Any help would be greatly appreciated. Right now when you click on the username it just takes me to the page of the member I'm currently logged in as, instead of the member I clicked on. Code: [Select] <?php echo "<table>"; $result = mysql_query("SELECT * FROM users WHERE looking='yes'"); while($row = mysql_fetch_array($result)) { echo "<tr><td>" . "NAME" . "</td><td>" . " " . "TIMEZONE" . "</td><td>" . " ". "SERVER" . "</td><td>" . " ". "CLASS" . "</td><td>" . " ". "RACE" . "</td><td>" . " ". "AA" . "</td><td>" . " ". "LEVEL" . "</td><td>" . " ". "EPIC" . "</td><td>" . " ". "CURRENT GUILD" . "</td><td>" . " ". "WILLING TO TRANSFER SERVERS" . "</td><tr>" ."<br>"; echo "<tr><td>" . "<a href=profile.php?ID=" . $row['ID'] . ">" . $row['user_name'] . "</a>" . "</td><td>" . " " . $row['timezone'] . "</td><td>" . " " .$row['server'] . "</td><td>" . " " .$row['class'] . "</td><td>" . " " . $row['race'] . "</td><td>" . " " . $row['aa'] . "</td><td>" . " " . $row['level'] . "</td><td>" . " " . $row['epic'] . "</td><td>" . " " . $row['guild'] . "</td><td>" . " " . $row['transfer'] . "</td></tr>"; } echo "</table>"; ?> |