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:
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
MySQL Conditional Statement
What I am trying to do is kind of like an advanced search. Basically, I have three dropdowns, for this I am going to use the example books: Three dropdowns, which are 1) Author 2) Language 3) Type (Hardback or Paperback) Typical search: I want to get a list of all books written by STEPHEN KING, that are written in ENGLISH and that are HARDBACK ok fine, but what if I just want to search for ALL books by STEPHEN KING regardless of the language or the type of book?? Heres the SQL i would use for all 3 "search parameters": PHP Code:
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:
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 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 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
Editing Mysql Database Row With Select Box
I have a small site, this small site has a few categories, now I can add items through my online admin area fine and delete them fine, but when it comes to editting them I am having some trouble, everything is working fine except the category column, because it is a drop down box I do not know how to have the category selected during the creation progress selected all the other info is loaded.
Select MySQL W/o Automatic Vars
I'm used to working on PHP4. This project is on PHP5, and they have the ability to automatically create variables from request parameters turned off. So now it looks like I'm uable to select/print data from an MySQL database. I know this is probably very simple, but can someone point me in the right direction? Thanks! Here's my code I'm using: PHP Code:
MySQL - What Do I Need? GROUP BY? Nested SELECT?
I am stumped (or maybe just too durned tired). Here's what I got... CREATE TABLE `nodecat_map` ( `nodecat_id` mediumint(8) unsigned NOT NULL auto_increment, `nodecat_cat_id` mediumint(8) unsigned NOT NULL default Ɔ', `nodecat_node_id` mediumint(8) unsigned NOT NULL default Ɔ', PRIMARY KEY (`nodecat_id`), KEY `nodecat_cat_id` (`nodecat_cat_id`), KEY `nodecat_node_id` (`nodecat_node_id`) ) TYPE=MyISAM; CREATE TABLE `nodes` ( `node_id` mediumint(8) unsigned NOT NULL auto_increment, `node_content_id` mediumint(8) unsigned NOT NULL default Ɔ', PRIMARY KEY (`node_id`), KEY `node_content_id` (`node_content_id`) ) TYPE=MyISAM; CREATE TABLE `text` ( `text_id` mediumint(8) unsigned NOT NULL auto_increment, `text_content_id` mediumint(8) unsigned NOT NULL default Ɔ', `text_text` mediumtext NOT NULL default '', `text_timestamp_dt` int(11) NOT NULL default Ɔ', PRIMARY KEY (`text_id`), KEY `text_content_id` (`text_content_id`) ) TYPE=MyISAM; Plus a 'CAT' table not shown, but referred to in NODECAT_MAP by NODECAT_CAT_ID. I don't want to spend too much time explaining how/why the tables are organized like this, but here's a basic rundown of their relationships: 1) NODECAT_MAP maps NODES to CATS (categories, basically folders), with many NODES associated with a single CAT. 2) A NODE is basically a document whose content is stored in a TEXT record, and in order to track multiple revisions of a NODE document many TEXT records can be associated with a single NODE. Here's what I CAN do ... Given a CAT_ID (in this instance "5") I can successfully return all records with the following query: SELECT ncat.*, n.*, txt.* FROM nodecat_map ncat LEFT JOIN nodes n ON ncat.nodecat_node_id=n.node_id LEFT JOIN text txt ON n.node_content_id=txt.text_content_id WHERE ncat.nodecat_cat_id=5 ORDER BY ncat.nodecat_id DESC, txt.text_timestamp_dt DESC ;
Question Regarding A MySQL SELECT Statement
I tried hunting for a MySQL specific NG and didn't find one but I did see that MySQL questions get asked here. If this isn't appropriate and you know of an appropriate NG then that would be great. In one table I have inventory... table name is "inventory" columns are.. ----------------------------- item_number item_name ----------------------------- 1 radishes 2 carrots 3 potatoes 4 oranges etc..etc Table two is "sold" ------------------------------ date item_number 13Mar 1 14Mar 4 15Mar 2 16Mar 1 What I am querying is the table "sold" for the Unique items (1,4,2) and then retrieving their names from table 1. My query below isn't working.. SELECT item_name FROM inventory WHERE inventory.item_number = sold.item_number; I am just now starting to get into complicated MySQL queries and actually the more I learn about it the more I love it.
Select & Delete Mysql Queries
i've try to insert and delete record at the same page, but it only can insert and can't delete the record. when i click submit button from the previous form, the record is insert into table B and delete from the table A. is the code correct? Code:
Trick MySQL Select Problem
I have a database table, which has field that could contain a single integer or a list of comma separated integers. Is it possible to match each row of that field against an array of integers and return those rows where any of the integers in that field are in my array? For example suppose I did the following: arInts = array(2,4,6,8,10); What I want to do is return all rows from my table where my field contains a single integer and it is in my array, or where my field contains a list of integers and any of those integers is in my array? Is this possible and if so how do I do it?
How To Corret This Mysql Select Query?
I convert some code from access to mysql. And I have a InboxMessage table which has From and To field. So, the query is like: select * from InboxMessage where To=12 12 is user id. This query works fine in access. But does not work in Mysql. I think the problem is the field To, which must be a keyword in mysql. So, how to fix this? I don't want to change the field, becuase this will need to change a lot of code.
MYSQL Select Using BETWEEN '1/1/2000' And '1/1/2004'
What is the syntax for a mysql select statement to select values between a range of dates. I am trying to use: SELECT * from net5 WHERE Transaction_Date between '6/7/2004' and '11/3/2004' My dates are stored as date_time in the database.
Using PHP And MYSQL To Select From Database Using Images
I'm trying to update a main page with a list of details matching a selection from a display of images that are displayed in a small window that have been selected from an image group using a select box in the main window, however I don't know how to do this and the main page is not receiving anything when clicking on an image so it's refreshing with empty data. I've seen many many pages giving examples of how to do this with select boxes or how to do this if only one entry uses an image shown in the small window, but the image display window is displaying many different small images not a select box and the database itself has multiple entries that use the same image. Can anyone help? I have a few instant chat programs if someone wishes to discuss this with me in real-time to see what it is I'm trying to achieve.
Conditional Loop
I have one table, "players" that has player info including start season (year). I then have a table for each season with player stats, i.e. games played etc called stats200X where X is the year obviously. I have no problem with extracting data from the current year, but what I would like to do is get data from previous years too. I was thinking about doing something like: (year) - (startyear), which for example could be 3. I don't know where to begin, but I want to be able to loop though previous years so that, if tables exist of course, I could do select * from stats{Y -1} display select * from stats{Y -2} etc Would I need to hard code this or is there a way of doing this though a conditional loop?
Conditional Login..
I have a form with a username & password field along with 3 radio buttons. What I basically want to achieve is if radio button A is checked it will post the username & pass to a.php, If button B is checked it will post the username & pass to b.php and so on for button C.
Checkboxes,conditional
Basically I have what seems to be a very small problem but I am driving ny self mad trying to figure out what the problem is. Here is what I have: I have a form with two checkboxes: <input type="checkbox" name="medicalcheck" > <input type="checkbox" name="dentalcheck" > the form is posting the a php file, decision.php, that simple checks to see if the boxes have been checked and performs an operation in either case. Here is the code:
Once Conditional Causes Error, The Other Doesn't...why?
There are 2 if statements at the beginning of this code snippet. The one that is currently commented out works while the one that is not commented out yields this error Parse error: syntax error, unexpected '{' in C:xampphtdocsench2index4.php on line 106 I am just not seeing why. Code:
Conditional Structures
I am wondering about conditional structures and the depth of nesting allowed, if at all. For example I know I can do this: Code:
Conditional Form
I want to condtionally display an HTML form. I havnt got a clue how it can be done, I suppose its the same way as putting html tables in php, but I cant get it to work. Here is the condtion: <?php if (!empty($pk)) { And here is the form: <form action="google.php" method="GET" name="deleteForm" > <input type="hidden" name="pk" value="<? echo $pk;?>"> <input type="submit" value="Delete"> </form>
Very Slow MySQL SELECT Query After 11 Records
I have a very weird problem I moved my database to new IIS 6.0 + PHP 4.3 + MySQL 4.0 setup. I tried to check with myphpadmin if everything works fine, but I couldn't browse my table (125 records). I used SELECT option and found out that SELECT query up to 11 records is ok, but after that, even if I choose to limit query to 12 records, it just hangs. I tried selecting from the beginning of the table and from the middle - same thing, but when I run query localy on mysql console, everything works fine
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 Soulbound 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 = ེ'") 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.
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.
Getting Form Info Into A Mysql Select Statement
I'd like to get user input from an html form into a mysql select statement. Here's where I'm stumped: $result = mysql_query("SELECT * FROM dept WHERE notes LIKE '%search-string%'",$db); I need to get the user's input into the '%search-string%' section, but I do not understand how to do this. I can hard-code a specific search string and it will work, but I want the users to be able to dynamically define the search-string. So, I created a basic html form and used the post method to grab their input, but now I can't insert that input into the mysql select statement. Any ideas? I think it should be easy, I just don't know how to do it. I've tried this: $result = mysql_query("SELECT * FROM dept WHERE notes LIKE '%$_POST["search"]%'",$db); But it doesn't work. Below is the form in html and the php file: <html> <title>Search Test</title> <head> </head> <body> <form action="search-db.php" method="POST"> <p>Enter Your Search: <input type=text name=search></p> <input type="submit"> </form> </body> </html> ----------------------------------------------------------- <html> <body> <?php $db = mysql_connect("localhost", "Anonymous"); mysql_select_db("computers",$db); $result = mysql_query("SELECT * FROM dept WHERE notes LIKE '%surplus%'",$db); echo "<table border=1> "; while ($myrow = mysql_fetch_array($result)) { printf("<tr><td><b>%s</b></td></tr> ", $myrow[notes]); } echo "</table> "; ?> </body> </html>
Displaying Select Multiple Box And Using Mysql Join
i have an edit page where the query lists all the information from the database about a business. each business can have multiple types so i made a many-to-many database and now i need to be able to show all the types that are in the db for each business on the edit page. here is what i have so far but it's only selecting the last type of business in the result. PHP Code:
Add Select Mysql Output Rows To Session
I'm using php and mysql to search records and print the results to the screen. Output looks like this example (with more columns of course) but is typically spread over 2-3 pages with 200 results. The [] represent checkboxes with the id value for each record: [] Hat [] Car [] Sweater [] Boat I just want to be able to let the user select which boxes/records they want to print and put these in an array. When they're ready, I'd like them to be able to view all the records from the array on a page. So, if they've checked records 1,5,8, and 12, I would query the database for these id's and output to the page. Sounds simple, but I can't seem to figure the multiple select and store via sessions out.
|