How To SELECT Records WHERE Field Contains A Particular String?
I need to SELECT records WHERE a string matches the content of a field...
eg. I have field values like:
Phone namePhone name pinkPhone name bluePhone name polka-dot
What I want is to have a MySQL query which selects ALL records which match the search term, eg. 'Phone name' returns all of the above, but not 'Phone':
Currently my query looks like this:
SELECT * FROM [table_name] WHERE [field_name] LIKE '%s' ORDER BY [value] ASC
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Select From Table Where Field = String
How to select all lines containg a string (located in $pastmove) in the moves column. I tried several ways, for example: $requete="SELECT moves, opening_id FROM suitemove where moves like '%".$pastmove."%'"; but did not succeed;
How Do You Select All Records In The Month You Are In?
I have records in the database - one of the fields is a date field. I want to select all records in the database that are in the month I am in. For example, if it is the 12th September 2002 today and I go to the page then it selects all records from September 2002. If it is the 4th June it selects all records in June etc.
Multiple Records Where One Field Matches
I need all of the records where the $topicID = 1,2,3,4 Here's what I have that's working off an array of checkboxes: $query = "SELECT * FROM expertise WHERE topicID = '$choice[0],$choice[1],$choice[2],$choice[3]'"; I know this is screwed up. The results are less than reliable. It appears to only pay attention to matches for $choice[0] and then lists results that don't match the other choices selected.
Copy Select Records To New Table
In the table Step I have multiple records for each given id. I want to save the current list of records for an id to a new Step_Old table so I can look back at what I had at a given point in time, since the records for an id in the Step table will change over time. Now the question... does anyone have a slick way to do this, or do I need to Select all the records I want to save and then save them one by one with a while loop into the Step_Old table?
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 Distinct Records Within 2 Separate Tables
I have 2 tables - 1) - paid counties 2) - free counties and I want to search both to find a distinct list of the counties used. Is there a way to search the first list (save the data into an array), then add ONLY the distinct counties from the free table into the array. Then read all the data out of the array sorted by CountyName,CountyID.
Array To Select Field
I need to echo the contents of an array to a <select> field. Whatīs the easiest way to do that? I could just: <select name="blaha"> <option>$array[0]</option> <option>$array[1]</option> <option>$array[2]</option> </select> The problem is that the numbers of "parts" (I donīt know what they are called) in the array is different from time to time, so first I need to check if itīs empty or not, and if it isnīt, echo it.
Having 1 Select Field Enable Another
I want to create a php script that displays say (for the purpose of adding to database): Customer Id # (as a select) Email (as a select) two other fields a customer may have more than 1 email, but each email is unique as is the customer id # i know how to populate the customer id # from the database but is there a way (without creating a new script and passing it customer id # (storing it as hidden in the next scripts form, and then limit the emails listed)) to disable the email select until the customer id # has been selected (which then populates the email select and enables it) in other words is there a way to do this in 1 script?
Auto Select Field
I have a contact form in php and want the first text field to be auto selected, my field is called 'First' id= First. is this php or java script?
Select Only Rows Where Certain Field Is Empty
Basically i need to select the rows from a table where the user is "$curr_user" and the "seen" field is empty. Then i want to count the rows and use the count in a javascript alert. Heres what i got so far: Code:
Automatic Select Form Field Default
I would like to allow registered users to my site the ability to change your personal information. Let's say the country in which they are in. The country field is a drop down list. So its supposed to read from the table and make the value the default. How am I going to do this?
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?
Hidden Input Field Inside A Select?
I need to get a field from the database and attach it with the loop that is created around the <select> options, however doing a hidden field won't work, as it isn't detected when in a <select> Code:
Populating SELECT Multiple Form Field And Inserting Into Db
I have an update form where I'm trying to populate a SELECT multiple field with a list of 48 categories, from tbl work_cat. And show, as SELECTED, the one or many choices that the user had previously selected from the 48 categories which are stored in tbl cat_relations as $relation_cat. Then allow the user to update their selections and update the database. But I can't get my form to work. First problem, I can't get the SELECT field on the form to show the categories, and then I don't know where to go from there. Below are my form page and my processing page. Code:
Excluding String In Select
I have been working on modifying this code to exclude the genre of Christmas from the query. No matter where I add a genre != 'Christmas' I get errors. Any ideas? I want to exclude any genres that are Christmas. PHP Code:
Select Each Word Match On A String
here if we give the keyword as sony discman shock . the keyword is the product name. here i have to select datas. here sony discman is the product name of same. shock is another product. here i separate the string using explode function, what the thing three records are retrieved. ie.,the same record of product name is retrieved twice.how to solve this .
Display Specifc Field From Explode String
I am trying to display a single field from an explode string. I have no idea how to do this. The script already explodes the string and loops the data displaying it in table format. Code:
Ordering Alphabetical In Secondary Select String
Does anyone have a suggestion how I can order a list with names in a secondary select string. The first string selects a number of locations where people work From this string I get several id's form people (in the location table there are no names but id's form the people table) that work on those locations No I make another select to get the name form the people table using the id I got before. I would like to have the table ordered alphabetical by the name of the people Since the number op people is very long is will be to slow working the other way around (first selecting people and then looking for the location) Example: Location 1 Name A Name B Name C Location 3 Name D Name E Location 5 Name F Location 2 Name G Location 9 Name H Location 7 Name I
PHP String Concatination With Html Select Combo Box
I have problem in PHP String concatination with html select combo box. There are 3 files addressbook.sql : concat1.php concat2.php In concat1.php , if we select User Name in combo box & give input as 3 in text box. It display following output subhash kanade,3 sk@yahoo.com But, it is not display in that way. So, please see that code & tell me correction. addressbook.sql -- Table structure for table `addressbook` -- CREATE TABLE `addressbook` ( `id` int(11) NOT NULL auto_increment, `name` varchar(50) NOT NULL, `email` varchar(50) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ; -- -- Dumping data for table `addressbook` -- INSERT INTO `addressbook` (`id`, `name`, `email`) VALUES (1, 'pramod kumar', 'pk@hotmail.com'), (2, 'vinod wagh', 'vinod@rediff.com'), (3, 'subhash kanade', 'sk@yahoo.com'), (4, 'ketan patil', 'kp@hotmail.com'); concat1.php <?php mysql_connect("localhost","root")or die("Database Failed"); mysql_select_db("pradeep")or die("Failed to Connect Database"); $arr=array("concat(concat(name,','),id)","email"); $str="select ".$arr[0].", ".$arr[1]." from addressbook"; $res=mysql_query($str) or die("resultset error"); echo "<table><tr><th>User</th><th>Email</th></tr>"; while($row=mysql_fetch_array($res)){ echo "<tr><td>".$row[0]."</td><td>".$row[1]."</td></tr>"; }
Check What Type (integer, String Etc) A Database Field Is
If i have a datebase field like so: $username = $row['username']; //after SELECT and mysql_query etc. how do i check what file type it is? i have tried using is_string to check it but it returns all fields back as strings, even the ones i know are integers. i would like something that would tell me the data tyle (integer, varchar, text etc). are there any other ways or am i doing this wrong?
Update Statement Causes Mysql Varchar Field To Be Set To Empty String
I have come across a problem that has me baffled. I am using PHP with MySQL 4.1.14. Whenever I execute an update statement against a specific table, some of the varchar fields do not get set to the new values, but get set to empty strings instead. I have simplified the code down to updating a single column in the table, but the same results happen when updating just the single column. Here is the stripped down code which causes the problem: $queryString = "UPDATE REGISTRATION SET passwd = '$pass'' WHERE id = 388"; $db = mysql_connect("hostname", "user", "pass"); mysql_select_db("CUSTOMER", $db) or die(mysql_error()); mysql_query($queryString, $db) or die(mysql_error()); Printing the query string after executing mysql_query shows the following query: UPDATE REGISTRATION SET passwd = 'test' WHERE id = 388 This query updates the column successfully when run directly through phpMyAdmin. When run through PHP using the code above then column is set to an empty string value. There is no error returned if I call mysql_error() nor is there any unusual info returned from mysql_info() (other than it telling me that 1 row was affected). Does anyone have any ideas what the underlying problem is on this one? Could be an attribute of the database table or columns that would cause this behavior? I have racked my brain for a while over this problem.
Displaying Priorty Records And Normal Records In The One Dataset.
I have a page which displays the records from the database and uses paging to display the records in groupes of 10 per page. I now want to be able to show results depending on the database field (display) in the database (can be set to either "full" or "limited"). If the record and the field display is equal to "full" i want to then display this record at the top of the record set and display all the fields. If the record is equal to "limited" i want to display different results and they must show after all the records which are equal to "full". I can't output two different recordsets as i use paging and only want to show 10 records per page. Code:
Populating A Second "select" Field
is there a way to populate a second select field in a form based on input for a first select without reloading and using only php? Code:
Can A Field Communicate To A Server And Return Information To Another Field Without Retrieving The Whole Html Code Again?
Iīve got a sql table which has 3 fields. Their relation to each other is like this example. | CARS | YEAR | PRICE | ford 2000 ford 2001 ford 2003 volkswagen 1999 volkswagen 2000 I am developing an ASP web page that modifies a specific registry. So, it loads the information to some fields, but the user will be able to change only the "PRICE" field. I have to create two selects, one for "CARS" and other for "YEAR". But the "YEAR" field will only contain the correspondent years for each car the user selects. Example: selecting "ford" in the "CARS" <select> box, only the years "2000", "2001", "2003" would be automatically loaded in the "YEAR" <selec> box. How could i implement it?
Multiple Select From Listbox And Execute A Sql Query Select Statement
Supposing i have a html form with 2 listbox and i name it status and resolution. So it goes <select name='status[]'>... <select name='resolution[]'> Then i have a another php page. $status = $_POST['status']; $resolution = $_POST['resolution']; Now my question is, how do i do the sql query statement? mysql_query("SELECT * from bugs where status=$status and resolution=$resolution"); The problem is, i select 3 options form the status listbox eg. new, closed, duplicate. And from the resolution, i chose fixed, invalid.
How To Update A Table's Field With Another Tables Field?
I need to take the state field from dt_profile table and update the dt_matchfinder with this state making sure the member_id field matches. the problem is the dt_matchfinder table has null set for many of the state field but in the dt_profile each member ID has a specific state and I need the same to be true in the dt_matchfinder table.
Select Statement - Select Random ID #
I have made up a page that pull info on 13 branches of stores onto one main page. It's basically there to display all the branches on one page... then you click on the one you're interested in and then you go to a more detailed page. Back to the main page. On the top, there's kind of a featured branch that has a bigger picture and bigger title but it's still getting pul pulled from the same table etc etc etc. In order for me to avoid favortism to one branch (and for other branches to start complaining) I want to ramdomized the order every time someone came to page but I have no idea how. right now I have a super simple select statement.
Attaching A String To A Normal Word Without Loosing The String
In my database I have content rows that are either called <contentname>_title or <contentname>_fulltext. now when someone clicks a link on the site it goes to index.php?action=<contentname> so I guess you see where im going.. when someone goes to such a section index.php sees $action is used and attaches it to _title and _fulltext, so u get: $action_fulltext.. basicly of cuz php now sees it as one string '$action_fulltext' and not '$action'_fulltext.
DNS Records
Hey everyone, I'm trying to get a DNS record of an IP using PHP's checkdnsrr() and getmxrr(). I used echo checkdnsrr($REMOTE_ADDR); and echo getmxrr($REMOTE_ADDR); but I receive an error that the PHP build does not support it, but I am using PHP 4.0.5 and in the manual, it shows that PHP 3 and 4 supports the two commands. Any help?
Next N Records
how do I create a "next n records" interface? I want to initially output a specific number of rows, and have a next/previous scenario where the user can click on either and scroll forward or back through the records. I'm currently outputting all rows through mysql_fetch_array: Code:
HOW TO GET HOW MANY RECORDS YOU HAVE IN DB
I finally discover the way how to get what I need. Let's look to my code: ----------------------- CODE ------------------------> $res = @mysql_query("SELECT COUNT(*) AS ToT FROM table_name"); $dato = mysql_fetch_array($res); echo($dato[ToT]); ----------------------- CODE ------------------------> With this code you will get how much records do you have in DB. PS: Whan you think that everything is over and that you are at bottom of trying push harder to see what is under.
Last 5 Records
is there an easy way to grab the last 5 distinct records from an unindexed database? (php/mysql)
Number Of Records
I want to find out how many records, but I am using LIMIT in mySQL so if set the limit to 20 and I have 56 records then it will display 20 instead of 56. I have been using: mysql_num_rows What should I be using?
What To Do If There Are No Records In The Database
I am pulling data from the database and displaying it using the code below: $db = mysql_connect("localhost", "root"); mysql_select_db("pyramid",$db); $result = mysql_query("SELECT * FROM table where area='Wales'",$db); while ($myrow = mysql_fetch_row($result)) { echo "blah blah"; } ?> What do I do if there are no records? At the moment it just doesn't display anything. How do I get it to display a message saying there are no records?
Updating Records
I am know to PHP i've been tring to do this **** for days now could someone PLEASE help me. Ok Im tring make an admin page where user can update multiple records at same time using checkboxes.Im using email as primary key. Here is the code **form page** <form action="update.php" method="post"> <input type="submit" name="submit" value="Select First 10 Names"> </form> **update.php** <?php if ($submit =="Select First 10 Names") { ?> <form method="post" action="<?php echo $PHP_SELF; ?>"> <hr size=3> <?php $query = mysql_query("select * from Names order by Last_Name limit 10"); while($row = mysql_fetch_array($query)) { $first_name= $row["First_Name"]; $middle_name = $row["Middle_Name"]; $last_name = $row["Last_Name"]; $email = $row["Email"]; $photo=$row["Photo"]; ?> <table width="100%" border="0" > <tr> <td align=right width=50%> <?php echo "First Name: <input type=text name="first_name" size="30" maxlength="40"value="$first_name" ><br> "; echo "Middle Name: <input type=text name="middle_name" size="30" maxlength="40" value="$middle_name"><br> "; echo "Last Name: <input type=text name="last_name" size="30" maxlength="40" value="$last_name"><br><br> "; echo "Email: <input type=text name="email" size="30" maxlength="40" value="$email" readonly><br><br> "; echo "Photo: <input type=text name="photo" size="30" maxlength="70" value="$photo"><br><br> "; echo "<input type="checkbox" name="email[]" value="$email"><b>Update?</b> "; ?> </td> <td align=right width=50%> <?php echo "$photo"; ?> </td> </tr> </table> <hr size=3><br> <?php } ?> <input type=submit name=submit value="Update Enteries"> <input type=reset> </form> <?php } if ($submit=="Update Enteries") { if (is_array($email)) { while (list($key,$value) = each($email)) { $query= mysql_query ("update Names set First_Name = '$first_name' Middle_Name= '$middle_name' Last_Name='$last_name' where Email='$value'"); } } } ?>
Need Help With Deleting Records
I'm trying to add a link on the display of a record to delete that record. The main part of the record is stored in pw_event, then there are several rating fields for that record stored in pw_rate, and there is also several records for the first record stored in pw_whois. I need to have a link that will deleted everything for that record in all three tables. Here is my display script: PHP Code:
Retrieving Records With Between
I am trying to convert my asp website to php. So far so good, but I am having a problem with my SQL Statement that needs to us the Between. Here is what I am using: $sql = "Select * From tblTrack Where DateEntered Between $start and $end"; the vars start and end come from the same form. I don't have a problem when I hard code the dates, but when I use the variables, it won't retrieve anything.
Delete Records
I`m just trying to figure out the best method to delete my records and wondered if it was possible to do a DELETE statement to remove any records that don`t match. Here is my code so far: $Query="select blah its huge:-)"; $RESULT=mysql_query($Query); $my_rows=mysql_num_rows($RESULT); for ($a=0; $a<$my_rows; $a++){ mysql_data_seek($RESULT, $a); $Array = mysql_fetch_array($RESULT); printf("%s<BR>", $Array['Email']);} My Query returns Matched Records, what I would like to achieve is deletion of the records that didn`t match, would it be possible to do that under the printf statement. So delete all the records in the table that don`t match up to $Array['Email']??
PHP/MySQL Records Per Row
Is there any way to have the records pulled from a mysql database display like this in a table: record1 | record2 record3 | record4 etc: I've been thinking about this for about three months and have yet to come to a good solution.
Inserting Records
I'm trying to insert as many as records as possible but less than 100 into a table. First, i get the count inorder how many to add and then depending on the count, i get so many blank form fields to enter. Now, I noticed something really strange. 1.Only the last entered record is inserted into the table. 2.For example, when I type a name, Let us assume "WORLD", only w is inserted into the table and the rest is not.It is the same with all the form fields.whether, i'm trying to enter text or a number,only the first character is inserted.This sounds weird. Could somebody pls tell me why is this peculiar behaviour Here is the code:
|