Select All Unique Collumn Entries In Mysql
Can anyone tell me how you can query mysql for all unique entries into a particular table collumn. Ive checked the manual but had no luck!
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
MySql Select Unique Rows?
I am have a table which contains recent search querys of another table. I am tryng to output this data into a list so the user can click, and re-run a recent search... The problem is that the table is full of duplicate searches from the same user. How do I select the searches without retrieving duplicates? SELECT id, term FROM project_term WHERE pid='$_SESSION[project_id]' Also, would it make more sense to store all serches of a paricular user, or stop the insert if the record exists? Is there a way I can do this without performing 2 queries (ie adding some sort of LIMIT or other xeyword to the INSERT query?) I can't make the column unique because two users could perform the same search...
MySQL - Select Specific Row Based On Unique ID
I am building a photography website in html, and have a pre-formated table in which i want to put a thumbnail pic, the date of the pic, the name, and links to different sizes of the image. In a MYSQL database i have a table with four columns: ID (INT, auto-increment), ImageName (VARCHAR), FileName (VARCHAR), Date (VARCHAR). I'm just getting started with PHP, and i want to either: have the information automatically inserted into my pre-made table via a php loop command or write a script which will allow me to only enter the id# and will subsequently insert the name and the date into my table, and which might display the image of the filename. I hope this is clear enough, I've bought quite a large book on PHP and have been browsing forums in an attempt to learn, but i can't find an example that inserts it into a pre-existing table.
How Do You Select Unique Instances Of A Field Entry?
If I want to select and display the 'county' field from a table for all records, I'll get a list of records, many of them repeated. How do I select and display only one instance of each record, effectively cutting out all the duplicates?
Deleting Entries From Mysql
I have business listings that I have pulled from a database(MySQL) and printed to the page, in an admin page, for review. I'm trying to write a script to add and one to delete the listing. I get an SQL error, 'check the manual for blah blah near " on line 1' Here is the 'delete script:
Get All Entries From Today (mysql)
I currently have a page that each time a user visits it, the pageid and timestamp is thrown into a mysql daabase. so the database looks like so: linkid time 3 2007-08-22 17:26:21 3 2007-08-20 17:26:21 3 2007-08-22 18:36:59 2 2007-08-22 18:37:21 What i need is for php to show the total amount of visits today as per a certain time zone (or if thats not possible, the past 24 hours) soo.. Search for all occurrences where linkid = 3 today for a specific timezone (or 24 hours) MORE SPECIFICALLY User 1: Lives in New York (EST -5) registers for my site and sends visitors to his linkid (3) After two days, this is what the mysql table looks like: linkid time 3 -=- 2007-08-22 17:26:21 3 -=- 2007-08-20 17:26:21 3 -=- 2007-08-22 18:36:59 But mysql time isn't Eastern time, its another timezone. So when a visitor comes to user1's page at 3pm EST, mysql registers the time as 2007-08-22 17:26:21 So... I want to first add/subtract the number of numbers in the mysql database depending upon the user, and then see the amount of visitors for the day.
MYSQL Entries Won't Update
I am trying to update some entries in a mysql database that will append the filename to the end of a thumbnail directory entry. So for example /images/thumb/ would become /images/thumb/12345.jpg. I am stumped because the below code gives no php or mysql errors but the entries are not updated in the mysql db! Code:
Hit Counter Unique Using Mysql
i want a hit counter that logs unique hits by ip address and logs it in a mysql table but only once then when the data is logged it displays the number of people who have visited i would prefer not to use cookies if possible e.g. the php could check against the table to see if that ip is there if so then dont log it??
Multi Entries Update To Mysql
Could someone help me to figure out how to upgrade multi entries to Mysql by using PHP? Say, I have a table on Mysql id Priority 1 Okay 2 wait 3 later 4 asap 5 hold Now I want to upgrade that table to: id priority 1 hold 2 asap 3 okay 4 wait 5 later Is it possible to upgrade multi entries with one submitt button? If yes, could you tell me how it could be done. I knew I could do it by each entry (submitt button). Update priority set priority='$priority' where id = '$id'
Selecting 4 Random MySQL DB Entries?
I have a table set up in my MySQL database called 'features'. This table has 10 entries, but I only want to select 4 random rows and display them out in tables.
Limiting User Mysql Entries
I have a script i'm making which is going to be used to search for reciprocal links on different sites and I have user levels such as free, paid, ect... I want to make it so that if the person signs up as a free user they can only add like 2-3 domains to be searched for their links. How would I limit the number of domains allowed to be searched? Would I limit the number of mysql entries allowed in the table for the domains?
Populating Dropdown With Mysql Entries
I would like to create a combobox in Flash which is populated with mysql data and programmed with php. For example: There are 3 entries in database .ie. apple, bannana, peach. Now these I want in combobox in Flash MX/flash5.
Day View Calendar / Mysql Entries
I am trying to create a day view of a lab resource reservation system. So far, I've been able to generate a day view table with php, using variables for start time, end time and periods. Periods represent intervals on the day view. I have two columns in the table: the first one starts at the start time (say 8:00) and there is a row for every time until the end time, each row time being increased by the period, ie. 8:00, 8:30, 9:00 where the period is 30 minutes and the end time is 9:00. My second column in the table is filled with unix timestamps representing the date for that particular row, so the 8:00 row on July 1, 2007 is represented by a timestamp of 1183291200. I then created variables to represent start and end times and date of a reserved lab resource. I did a little switch statement in my second column of my table saying, if that row's timestamp equals the start or end time of my reserved resource, than give it a certain style. All well and good, except I need to tie this into a mysql database where the reservation details (start, end, date) are stored. Where I am getting fuzzy is how to integrate the query results from the database into my little system. I would like to have that second column pick up the results from my query and display the reservations, but I'm not sure now to do that. I'd like to post the code here, but I'm not sure how to post php code on these forums without getting yelled at for doing it wrong (I did that once, can you tell?)
Get Mysql Unique Column Fields
I have data with the field name "monthyear" and I am trying to get a list of all the different field names without repeating like "may2003, january2001, june2002", this is for my news script i am making, im going to use it to make an archives page which is organized by month any ideas?
Automatically Add Unique Id To Existing Mysql Db
I am working on a MySQL db (+/- 18000 items) which was converted from FoxPro. But is doesn't have a unique id-field and I was wondering how to add such a field and the incremented numbers in it automatically, without having to enter 18000 unique numbers.
Unique Code Using 4 Numbers (with MySQL)
On my site, visitors get a code, existing of 4 numbers (randomly picked using rand() for it). This code is put into the database. How can I get a unique code (so no doubles) each time php gives a random one ?
INSERT Into Mysql Alway Make Two Entries
I code some site and because Im a freak I made my own session-handling. When a user open up my site it will check if there is a ssid in the url if not generate one. this will be done by a function generate_ssid() and works fine. next step is to register the ssid in the table session this will be done by the following code: ****************************** function ssid_register($ssid,$login,$uid,$admin){ $connect = mysql_connect( $GLOBALS["db_host"], $GLOBALS["db_user"], $GLOBALS["db_password"]) or die($GLOBALS["db_error"]); mysql_select_db($GLOBALS["db_name"],$connect) or die($GLOBALS["db_error"].'<br>ErrorCode s.001-con'); $result = mysql_query("INSERT INTO session SET ssid='$season',ip='$rip'",$connect); echo ($rs); return; } ******************************** I redesigned the INSERT INTO part into all possible syntax but everytime I look into the db, there are two entries with two DIFFERENT ssids. The only way it works correct is to dont use a variable on the first place. Means if I use ssid='godhelpmetofindaworkingsolution' it works great but is not realy what I want. As told above a "INSERT INTO session (ssid) VALUES ($ssid)" also has the effect of two new db-entries.
Populate MySQL With Multiple Text Box Entries
I have about 300 rows of mysql data which I have chosen to diplay with a text box at the end of each row, that is available for adding comments. I would like to be able to add comments to entries and then have an update scripte that would take the text box, named "MC" and place the data in its row identified by a hidden field which would corrrespond to the Primary Key of the MySQL Database. I've done something similar using check box arrays, ie. Checkbox name="MC[]" My question is whether I can write a script that would test for a value in the corresponding text box, and update the MySQL data accordingly. I have also provided in my display script that if the MC column is already populated in MySQL it will not display in the form.
Unique Situation, Fopen, Mysql Can't Be Called
I've run some tests and I have to conclude that mysql and fopen doesn't work when you call it in this way. I don't understand why, it's got to be either one of 2 things: a) this just can't be done, and I'm ignorant of why b) there is a workaround and/or i'm doing this the wrong way Hopefully someone can enlighten me? Here's the situation: HTML PAGE img src=script1.php SCRIPT1.PHP //redirects to script2.php header(Location: $urltoscript2) SCRIPT2.PHP //writing to a file doesn't work //writing to a table in mysql doesn't work header(Location: $urltoimage) Information can be passed via query string from the html page to script1, to script 2, and the image does get displayed, but mysql and writing to a file just won't work unless you call script2 directly. I have tested this in the following way: 1) I tried accessing the html page which displays img src, script2.php didn't write to mysql as intended 2) I tried accessing script1.php directly, script2.php didn't write to mysql as intended 3) I tried accessing script2.php directly, script2.php DID write to mysql successfully Same goes for writing to a file.
Random Unique Number - Joint MySQL
It has been asked of me to create a randomised unique number. I have generated the random number, however I want to make it unique by cross referrencing the database. IF the number has already been stored it shall REPEAT the function until the new random number is not in the database. When it is unique it shall then be stored in the database. Code:
Deleting Duplicate Entries From MySQL Database Table
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone | ------------------------------------------------------- | mr x | 8th lane | 124364 | | mr x | 6th lane | 435783 | | mrs x | 6th lane | 435783 | | mr x | 8th lane | 124364 | ------------------------------------------------------- Quote:
Generating Unique Primary Keys For MySQL With PHP (overkill)
I'm looking at some of my MySQL databases that rely on auto-incremented serial numbers for primary keys and I've decided it's time to come up with a better way as my projects are becoming increasingly complex. I wouldn't want to be in the position of writing a solution that used up the 32,768 keys per month their SMALLINT serial number generator (just a guess) was producing and left thousands of customers stranded on Christmas day. [story] I've put this function together that (as shown) has 3636 possible keys, or a little over 1.46 quindecillion. (It scales easily to smaller or longer keys.) function produceFib($length) { $val = '' for($i=0;$i<$length;$i++) { $str = 'abcdefghijklmnopqrstuvwxyz0123456789' $shuffled = str_shuffle($str); $val .= substr($shuffled, 0, 1); } return $val; } echo produceFib(36); So here's my questions: - Is this overkill? - Do I need to do something more complex? - How do you do it?
Update If Unique User And Unique Id?
I have a site which lists some links on a page.Each link gets parsed to "/out.php?entryid=x" When they do this, my out.php updates the number of times that has been viewed It then pushes them on to the appropriate link. To prevent "gaming" of the link count, I want to try and use the IP or a session or something that will mean users can not inflate the count of any one link by more than 1. Code:
Date Dropdown From Mysql Date Entries
For the PHP gurus out there, here is what I want to do: create a dropdown list of available dates from a mysql database date entries. But the dropdown/s should have 3 separate fields in month, day and year which in effect shows only those months, days and years that have corresponding entries from the database. Planning to use this in the archive section of an online news publication so people can select issues to view via dropdown list that have corresponding entries only.
MySQL Select
Just a qucik question. I need to display everything from the table where the data is not null, apart from username, as they'll always have a username. So far I just have this, which is on the assumption they have entered their name. $get = "SELECT * from profiles WHERE name IS NOT NULL LIMIT 30"; Is there a way I can basically make it say. Select * from profiles where * but username is NOT NULL?
Php/mysql Select
I need to retrieve the most recent additions to a table where column name='$string' My question is that of these records returned, I need to diplay THE MOST RECENT record in one place on the html page, and then display the others (in order from newest to oldest) in another place... I can pull the records with a select statment, and I understand the ORDER BY statement that follows, but how do I split the results as above? ** The records have a 'date/time' column, and a 'category' column that I will use to perform the select statement...**
MySQL SELECT
I have a page where I am trying to list data from a select statement. However, I am only getting one record from this SQL statement in a PHP script, but over 3200 records with the same statement in phpMyAdmin. Am I doing something wrong? PHP Code:
MySQL+PHP Select One Row
I'm sure it has been asked a thousand times before, but still: How can I access a particular row in my MySQL table via PHP? The background is just to update the values of one row in the table via a html form with the old values already filled in. What I tried so far ist sth like this: $row=mysql_query('SELECT * FROM names WHERE ID=$entry'); for ($i = 0; $i < mysql_num_fields($row); $i++) { echo("<td>$row[$i]</td> "); } The mistake should be that mysql_query does not return a vector, but still a table... Does anybody have a good idea how to solve that problem?
MYSQL SELECT?
In my code I am trying to SELECT username and UsrRights When I Echo out the SQL query I do not get anything back. Why am I not getting anything echoed back? Code:
Mysql Select Via Php
Everything works. I just want to make a table of results show up in alphabetical order. I have mysql select whole table. I want to take the mysql select and select the whole table with one field alphabetically. A to Z. How do I do this?
Select From A Mysql Table
I want to pull one field from a mysql table. How do I do that? Do I use SELECT? The field name is $sip_visitornum. And I want the last value that was inputted in to the db. I already have the code to get the visitor number but I don't know how to display data from the database properly. Thanks.
MYSQL - Select XX Months
I have a database set up, with one of the fields is a month - "200611" = November 2006 "200610" = October 2006 "200609" = September 2006 I was wondering, I know how to sort descending etc.. - Is there a way, to (add to an existing search criteria).. select all records in the last XX months.. IE, If I only wanted the last 2 months, it will only select records in October & November 2006.... or September also - if I want 3 months... (I have records going back to April 2006) Im guessing the 'unique' function will be used, but im not sure how to select XX months.....
Negative SELECT In Mysql?
How does one retrieve the rows in a select statement that DONT match the select. select CarIndex FROM DealerCatalog, BigCatalog WHERE DealerCatalog.CarIndex=BigCatalog.CarIndex finds all the cars in the dealer catalog that are in the bigger distributor catalog. How do I do the opposite in a single sql statement i.e. all the dealer cars that AREN'T in the big distributor catalog?
Mysql Query - Select Any
I have the following sql statemant to search a mysql database that gets if values from a form with combo box's in. SELECT * FROM hottubs, manufacturers WHERE manufacturers.manid = hottubs.manid AND hottubs.type = '%s' AND hottubs.dimlength <= '%s' AND hottubs.dimwidth <= '%s' AND hottubs.dimhight <= '%s' AND hottubs.seatsto <= '%s' AND hottubs.shape = '%s' ORDER BY $thesearchtype_search. Everything works fine except I want to add a select "any" from the shape combo box. I really need a way of cutting out the last " AND hottubs.shape = '%s' " if the $_GET['shape'] = 'any' Will this work using a variable as shown below?? IF ($_GET['shape'] != 'any' ) { $shape = AND hottubs.shape = '%s' } SELECT * FROM hottubs, manufacturers WHERE manufacturers.manid = hottubs.manid AND hottubs.type = '%s' AND hottubs.dimlength <= '%s' AND hottubs.dimwidth <= '%s' AND hottubs.dimhight <= '%s' AND hottubs.seatsto <= '%s' $shape ORDER BY $thesearchtype_search I have only been doing php about a month so go gentle!
MySQL SELECT Returns.
How would one go about retrieving data from a MySQL table, and then breaking it up into groups of, for example, 5. What I am trying to do is pull search results from sed table, and then be able to have links at the bottom that would be like "<Previous 1, 2, 3, 4, 5, 6, Next>" where the numbers represent the dynamic amount of pages listing the search results.
(mysql) Select And Indices
Trying to write a php script where the user will enter the row number (index) of a record. Say, for example, user wants record 55: [MySQL]: select * from MyTable where Index = "55" where Index is an autoincrement value, and also an index. Unfortunately, MySQL barfs on this type of instruction. Doesn't seem to want to let me access Index values...
Select Multiple & Mysql
What's the sql should look like to get all possible data when using multiple select, such as: <select name="hostfield[]" multiple> PHP Code:
Conditional Select From Mysql
I have a mysql database which stores race data that I want to open up to users for viewing. I want the user to be able to select various subsets of the data according to the parameters: race, gender, age, and type (and maybe sometime, by name as well). This is BOTH a mysql question and a php one, as I ask for a more efficient solution (see bottom this post). Here is a snippet of how I am implementing the mysql statements to select only the exact subset of data. PHP Code:
MySQL Select Case
I'm trying to get the venue in the 'List' column when in contains a value. But if the venue Is Null then place the event in the 'List' SELECT CASE WHEN event Is Null THEN venue Else event End as 'List' ,DATE_FORMAT(fld_date, '%M') as Monthly[color=blue] >From na_statistics[/color]
MySQL: Select Row Numbers
I would like to be able to do something like this... select name,dob from employees where [rownum] > 10 and [rownum] < 20; .... results from this would show me data from the 10th, 11th,... and 19th row.
MySQL Select From (no Column)
Is it possible to select from a table using WHERE without putting in a column name? Kind of like this: mysql_query("select * from flights WHERE LIKE '{$searchfield}'");
MYSQL Select Code.
Im trying to make this somewhat statement which says through mysql_query(); somthing like: ("SELECT username = $user FROM user_info WHERE rights = $rights"); // then put $rights which has been never been valued before $_SESSION['RIGHTS'] = $rights; So correct me if im wrong i want to do something like this. if anyone could help me form this up in a formal mysql_query manner, since ive done a lil search but didnt find much about it.
Using PHP And MySQL To Populate (select) Menus
I am a newbie to php *gasp* and I am trying to make a <select> drop down menu, but I want the menus populated by information from a field in my database. There are a bunch of entries in the field MUD, that are identical......I would like the menu NOT to repeat identical names. EX... Each name only once, even though it is in the database many times.
MySQL: Insert...select - Update?
I was reading about insert select http://dev.mysql.com/doc/mysql/en/insert-select.html Thought this may be a better way to perform a query I'm doing. The differenc is that I need td select from one field, and then update another field in the same record (it is a backup/undo field). Is there a way to do this in one query? It's a large chunk of data (longtext) so I thought this would be faster than the alternative...
Select List/Menu Using PHP And MYSQL
Here is my code: <select name="country" class="sidelinks"> <?php do { ?> <option value="<?php echo $row_AllCountries['country_ID']." ";?>"<?php if ($row_AllCountries['country_ID'] = $acountry) { echo "selected"; }?> > <?php echo $row_AllCountries['countryname'];?></option> <?php } while ($row_AllCountries = mysql_fetch_assoc($AllCountries)); ?> </select> A few words to describe: -$row_AllCountries['country_ID'](get from MySQL) is a unique country ID number -$row_AllCountries['countryname'](get from MySQL) is the name of the country -$acountry is the country ID number that i want to be selected when the form loads I have all the values and country names named OK...the only problem is that when the form loads it selects the last country.
Mysql SELECT With (varchar) Variable
I have been sent from the mysql forum to here, apparently my problem is strictly PHP related? This one is easy I expect - I need to make a variable that is readable as varchar by mysql - I just think it will be faster to ask here than search all the PHP/MYSQL functions to get it right. In my SELECT statement I would like to pass names (varchar in my database) via a variable called $membername e.g.: PHP Code:
[mysql] SELECT COUNT(*) Question
Is something like the following possible? SELECT products.id, count(*) as counter FROM products, keywords WHERE keywords.keyword in ("bla","hi","hello") AND counter > 2; Can't get it to work :/
Select Count(*) Prblm With PHP & MySQL
I am trying to create a login script that will check to see if it is a valid user. I have tried two different ways but neither one seems to work. Here they are: Attempt #1 $connection = mysql_connect($host,$user,$pswd); $result = mysql_db_query($db,$query,$connection); $cntr = mysql_result($result,0); if($result == 1) This gives me this error: Warning: Supplied argument is not a valid MySQL result resource in /home/lyates/gtstatskeeper-www/corecode/login.php on line 33 Attempt #2 $selectresult = mysql_query($query); if(mysql_num_rows($selectresult) == 1) This gives me this error: Warning: Supplied argument is not a valid MySQL result resource in /home/lyates/gtstatskeeper-www/corecode/login.php on line 33
|