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


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.


MySQL Select Unique Values Based On One Or More Possible Clauses?

So there is this database table:and this array with selected options:

$options[1] = 1;
$options[2] = 5;
$options[3] = 3;


View 3 Replies View Related

Unique Code Based On Users Unique Email Address Inserted Into Mysql Table?

I have a mysql table which will store users email addresses once submitted (each is unique and is the primary field) and a timestamp. I have added another column called `'unique_code' (varchar(64), utf8_unicode_ci)`.

a) Generating a 5 digit alphanumeric code, ie: 5ABH6

b) Check all rows in 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.

The table should look like:

email unique_code timestamp 5ABH6 2011-03-15 14:51:18 9QRE0 2011-03-15 14:51:24

What code must I put and where?

My current php is as follows:**

PHP Code:

require "includes/connect.php";
$msg = '';


View 6 Replies View Related

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...

View 1 Replies View Related

Select A Unique Mysql Line Without While?

I want to select only unique values with php/mysql.

I can do it with many line, but I forget how to do it without while... :)

Here is the code that I want to do without while.

$request_1m = "SELECT date1, date2 from mytable";
$result_1m = mysql_query($request_1m,$db);
while($row = mysql_fetch_array($result_1m))
/* Get the data from the query result */
$date1_1m = $row["date1"];
$date2_1m = $row["date2"];

View 4 Replies View Related

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 1 Replies View Related

Select A Specific Row In A Mysql Table?

how do I select a specific row in a mysql table?

View 5 Replies View Related

Select Specific Phrase From MYSQL Database

I am working on a World of Warcraft guild's website and I am trying to create a page where players can select different kinds of gear, i.e. the gear with the most Stamina.

All the player's items are stored in the database and every item have a field in the Items-table containing the item's tooltip. This could look something like:

Boots of the Nexus Warden
Feet Cloth
97 Armor
+27 Stamina
+17 Intellect
Durability 35 / 35
Equip: Improves spell hit rating by 18.
Equip: Increases damage and healing done by magical spells and effects by up to 21.

I then want to select the item with i.e. the most Stamina for all the different slots; Head, Chest, Legs etc.

If I write this:
$query = mysql_query("SELECT substring(item_tooltip, LOCATE('Stamina', item_tooltip)) AS maxor FROM roster_items WHERE member_id = &#3962;'") or die(mysql_error());

It returns the following:
Stamina +17 Intellect Durability 35 / 35 Equip: Improves spell hit rating by 18. Equip: Increases damage and healing done by magical spells and effects by up to 21.

But I want for it to show the leading characters also (in this case "+27 " before "Stamina") and then not show anything else after the phrase "Stamina". So it shows "+27 Stamina" and nothing else for the above mentioned item. How do I accomplish this?

And then, secondly how do I then get it to show only the item with the most Stamina after it selected the above?

Hope this makes any sense.

I've tried to search these forums and found something a little along the lines of my problem but haven't been able to adjust them to my needs and I therefore need your help which will be greatly appreciated.

View 1 Replies View Related

Select Specific Rows In A MySQL Table?

How can I select specific rows in a MySQL Table? So instead of selecting ... ORDER BY date can I do something like SELECT * FROM Posts FROM(5) TO(10) ORDER BY date DESC where I would be selecting Posts 5 to 10 in the descending order?

View 6 Replies View Related

Select Specific Content From Mysql Database?

I need to echo text from a specific ID in my table..If i use

$navquery = "SELECT * from content


View 1 Replies View Related

Select A Specific Row From A MySQL Result Resource?

My code generates a random number and then I want to select the row from a result set corrosponding to that number.

I'm new to PHP & SQL and I can't find a way in the manual to select a specific row from a result resource, only mysql_fetch_array() which seems to just take the first row and then move some invisible pointer on to the next one.

My code looks like this, but surely there is a more efficent and elegant way?


// Loop through results fetching the first
// row until I reach the <$rndTestNo>th row
for ($i = 1; $i <= $rndTestNo; $i++ )
$row = mysql_fetch_array($result);

View 2 Replies View Related

Select Based On Path In Mysql?

I have a column id, a column parent and a column path that is a materialized path.It looks like

1 | N | 1
2 | 1 | 1/2
3 | 2 | 1/2/3
4 | 3 | 1/2/3/4

View 1 Replies View Related

MySQL: Select Based On First Letter Or Number

I'm working with a fairly large database of company names, and I'm looking for a way to display them all in a format similar to the following:


Click on a letter, and all companies that start with the selected letter are displayed.

I have it ALL working just fine, except for the numeric selection. Several companies start with numbers (ie. 3Com), and I would like to display all of those (0-9) when the pound symbol is clicked on. Code:

View 2 Replies View Related

Select A MySQL Connection String Based On The Value Of A Variable?

I would like to connect to different databases depending on the value of a variable. I was thinking of trying something like this:

if ($city = 'phoenix') {
mysql_connect("x", "y", "z") or die(mysql_error());
mysql_select_db("databasename") or die(mysql_error());
if ($city = 'losangeles') {
mysql_connect("a", "b", "c") or die(mysql_error());
mysql_select_db("databasename2") or die(mysql_error());

Is this possible?

View 3 Replies View Related

Display Results From A MySQL Database Based On The Value Of Two Select Lists?

I'm trying to display results from a MySQL database based on the value of two select lists.Here's the html I'm using for the form outside the PHP.

HTML Code:
<form id="form1" name="form1" method="post" action="<? $PHP_SELF?>">
<select name="holtype" id="holtype">[code]....

However when I go to run I get the following error

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:wampwwwCaravanprices.php on line 114

View 1 Replies View Related

Html - Populate A Second Select-tag With Options Based On The Option Selected In The First Select-tag?

I will draw the options for the second select-tag from a database.

View 4 Replies View Related

Unique Visits/hits To Specific Items Using Cookies/ip?

I use a simple MySQL table to count day hits for specific pages/items in a website. Using 'id' column for page/item ids, 'date' for the day of the visits/hits, and 'hits' column for the number of hits.Everytime someone visit the page the value of hits for that specific date is updated to +1.But, the value is updated one more time each time the page is refreshed or revisited and I need a way to save the page ID in a cookie or the visitor IP in the database to update the hits just one time.I never worked with cookies so I dont really know how to do it and the limitations of the data than can be stored in a cookie.I think saving the IP adresses of the visitors in the database is a really waste of queires and bandwitch and I read that its not always possible to get the real IP and this can make some problems and some hits not updated.I also read that its better not to use GLOBAL variables too much...

View 1 Replies View Related

Generating Specific Unique Random Alphanumeric String?

I want to generate a unique alphanumeric string having specific length and having specific characters used. For example I want to create random string having several alphabets initially then some numbers then some alphabets again.


View 1 Replies View Related

Uniqueidentifier - Unique ID Based On Username / Email

I have an email address and I want to create a unique ID based on it, so say email is [URL]... that turns into 66wyy7eu. Ive found a close solution [URL]... but it needs the input to be numeric

View 6 Replies View Related


I'm running a query which currently outputs all the dates in a field, how do I display non-myltiple dates, that is is a date is output, no dupliccate of it woldbe produced. SELECT UNIQUE date from activity.

View 2 Replies View Related

Create A Unique Session Based On An Existing Variable?

I'm trying to create a unique session depending on a customers ID.


However, whenever I access the session, I get the same data regardless of the $customer_id.

View 3 Replies View Related

Select A Unique String

I've got a field in my MySQL DB which has a user ID or their IP. I want to select the last 5 rows which has it's own ID or IP Code:

View 8 Replies View Related

Select Unique Combination

I want to find unique combination of two fields in a table, I tried either this:

SELECT distinct(field1), distinct(field2)
FROM `someTable`

SELECT distinct(field1, field2)
FROM `someTable`

View 3 Replies View Related

Only Selecting One Unique Object On SELECT

I'm in the middle of working with an auto complete script for a tag field. At the moment when doing a 'select tags from table' (to populate the array which feeds into the auto complete script) I might get results like this: Code:

View 2 Replies View Related

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?

View 6 Replies View Related

Select Unique Visitors Per Date Interval?

I've found a few query strings related to what I'm looking for, but nothing that does this. Basically, I have a graph that needs to display unique visitors per time interval (hour, day, month, or year). So, a graph similar to Google Analytics or this Analytics Graph. The table has a visitor ID column and a timestamp column (in the style 0000-00-00 00:00:00). I need to be able to select the unique or total visitors per interval (eg. 32 visitors on the 5th, 30 on the 6th, etc). I guess my question is, is there anyway to do this efficiently with just a query? Or will I need to use PHP to get all the data (problem with that is that I would have to do a query for each point on the graph, not efficient)?

View 3 Replies View Related

Design - Use Script To Show A Unique Header IMG Based On Path On A Drupal Website?

I have a Drupal site that needs to display a unique header image based on the path. I have found some helpful code. It gets me close to where I need to be, but not all the way. I have pasted it at the end of this post. The issue I am having is that it bases the banner image off of the characters after the first "/" after in the URL. For example, returns a banner of header-FORUM.png.

I need it to work a little differently. I would like it to base the banner returned off the characters after the second "/" after in the URL. For example, [URL] should return a banner of header-TERM.png. Here's the code I mentioned earlier via AdaptiveThemes (FYI, there is a comment on that page that attempts to solve a similar issue to mine but I can't get it to work).

// Return a file based on the URL alias, else return a default file
function unique_section_header() {
$path = drupal_get_path_alias($_GET['q']);
list($sections, ) = explode('/', $path, 2);............

View 3 Replies View Related

Pull Unique Key Names From Json Data Like SQL Select Distinct

I have the following json data:


The idea here is that I want to take this data and use parts of it. I want to create a list of the "category's" that are in the data. The problem is that there is and will be multiple items with the same category. So my list will have duplicates that I do not want. The following is how I am getting the data and converting it for use:


So I guess muy question is I want to take the $likesArray and pull out all the unique Data->Category->names. Also will want to do sorting, and other things but I will get to that when the time comes.

View 1 Replies View Related

Get Sql Result Based On A Specific Subpage Id?

I am trying to get sql result based on a specific subpage id and also using the like. The subpage id does not seem to work and have tried to different codes below.

Code: [Select]$sqlItem = "select * from tblsubpage WHERE subpageid='5' || title like "%".$searchfor."%" || paragraph like "%".$searchfor."%"";
and also tried
Code: [Select]$sqlItem = "select * from tblsubpage WHERE subpageid='5' AND title like "%".$searchfor."%" || paragraph like "%".$searchfor."%"";

View 3 Replies View Related

Query Mysql Based On GPS Latitude And Longitude Columns Based On Relative Distance

In an app I'm building, One of the features i'd like users to be able to discover people around them easily. I'm using the GPS to get the latitude and longitude, then storing that information in the mysql db along with the other user information under a column for latitude and another with the longitude. What's would the best practice be to do a query that looks at the person whos making the query's information and then have it find the closest possible relatable lat and longitude then start there and limit it to 24 results? And furthermore, how would I remember where it stopped so I could allow another query to start where it left off and return more getting further and further away.

Basically, to generalize how can I do a mysql query that starts as close as it can to 2 latitude and longitude points that I supply and then have it grab the next 24 sorted by closest to furthest? I feel like its going to be hard to do because its being based on 2 columns. Is there a way I should/could be combining the GPS values into 1 column so it will be easy to find relative distance? Maybe I could somehow get the zip code (but then that might cause non US problems). I'm not sure. I'm stuck. If anyone has any experience on this, or is a MySQL Master

View 3 Replies View Related

Stripping Out Specific Tags Based On Attributes?

This is a toughie. Let's say I have a string of html that contains several nested spans. I need to completely remove just some of the spans, based on their specific attributes:


<span style="text-decoration: underline;">
<span style="font-size: small;">Earlier this month</span></span>
<span style="font-size: small;"> (“ObamaCare as a Moral Clunker</span>
<span style="font-size: small;">”</span>


In the above example, I want to remove any spans that have a style of "font-size: small", but leave any other spans.

I've been playing around with DOMdocument, but I can't figure out how to get it to work -- all my objects are empty.

View 13 Replies View Related

Copyrights 2005-15, All rights reserved