Number Of Identical Entries In MySQL DB Column
How do you display the number of times a particular entry appears in a column of a database?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Multiple Entries In On Column/List Box
I'm creating a page where members can edit their research information. I'm going to have 12 List Boxes, each with about 20-25 words. I want the user to be able to choose as many as they need (by control+click) - and store them all in the database. I expect each member to only have about 4-5 .. but you never know. The information they submit, all 4 or 5 or however many keywords, will need to be easily searchable on the main page. I also am going to need to make it easy for them to edit/update their keywords. My question is - which is the best way to do this? Do I dumb all the selected values into one column of a table? then when doing a search just do a text search? And how do I implement the update page? I know how to show previous text in a text form field, but is there a way the options they chose can be pre-selected when they go to update their research?
Determine Number Of Entries
I have a form in which the user can add more textboxes as need be: Ing1 Ing2 Ing3 .... There could be 1 input or there could be 30... How can I, in php, determine the number of input controls so that I can then loop through them one by one and process their data?
Limited Number Of Characters Returned From Column
I'm trying to create an overview page that will show all of the columns from a particular MySQL row. However, as some of the columns can get long, I'd like to be able to limit the amount of text displayed on the overview page to about 1000 characters and have a "more" link on the end that would bring the user to a detail page. How would I limit the number of characters displayed?
Highlight/bold Largest Number In A Column
i have my database setup to show weights of the item. How can i tell my php script to highlight the cell in the table or bold the weight in the table? i hope what im trying to say makes sense. instead of sorting it by the heaviest weight i just want to be able to highlight/or bold the heaviest weight so the names of the items stay in alphabetical order. and i will be able to tell which item is heavier.
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:
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?)
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.
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:
MySql Column ??
What i want to do is this. I have an field in one of my database tables with money price of product, i want to display the total amount of the table, i try to use "select sum(fieldname) from table where" but is not working.
PHP Code For Max Val In A Column In Mysql
I am trying to display the maximum value of a field called 'quesid' when the value of a other field 'id' is 15...i have to do this in php..i have to display this max value...
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}'");
Alter A MySQL Column With Php
I have a table named sentcards with a field called cardid with a current type int... I wish to change the type int to bigint(30) with an attribute that is unassisgned and a default of 0... This is my code:
Displaying Records, But Not Identical Ones.
I have a table with several rows. One column is "State", where, of course, a state is listed. I'd like to query the database and list all states in the rows, but I don't want multiple instances of the same state? How can I prevent it from showing:
Loading A MySQL Column Into An Array
ok i have a forum i am creating and i store the id of the forums where people are moderators in their userinfo. i speperate them with a comma. i need to either load them into an array or use explode() but i'm not sure how to create the array. i'm thinking that using an array would be faster because i could search in it to find out if the user is a mod.
Displaying MySQL Column Names Using PHP
I'd like to be able to display the column names of a table on a page. Is there a way to read that information in using SHOW? And then to display that information again? Or would I have to store these names in a seperate table and display these values? I tried this, but it sure didn't work: $result = mysql_query ("show columns from industries"); print ("<table>"); if ($row = mysql_fetch_array($result)) { do { print ("<tr><td bgcolor=#cccccc>"); print $row["field"]; print ("</td><td bgcolor=#cccc00>"); print $row["type"]; print ("</td><td bgcolor=#cccc00>"); print $row["null"]; print ("</tr>"); } while($row = mysql_fetch_array($result)); } else {print "Sorry, no records were found!";} print ("</table>");
Check If Column In Mysql Exists With Php
I wanted to know if you can let php check if a column exists in a table. cuz i have a 1 script script and i want it to check a table for having the following columns and if 1 o fthem is missing it would automaticly add the column.
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?
Should I Add A Multi Column Index To MySQL?
I have a mysql table. Two columns in the table are used to pull out stories from the table. One of the columns stands for categories of the stories, and the other column is the primary key and has the id for each story. I am thinking of writing queries like this: mysql_query("SELECT * FROM articles WHERE category='Science_Fiction' AND story_id=ཀྵ'"); I am wondering if I should create a multi column index that covers both "categories" and "story_id" columns. -- INDEX (categories, story_id) Would this increase performance?
Numeric Column Names In Mysql?
i am trying to create a table with a column name called 2004. But I keep getting a mysql error? Is there any workaround? Unable to execute: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near �� TEXT,2004_reference TEXT,2005 TEXT,2005_reference TEXT,200 CREATE TABLE test (id int(6) NOT NULL auto_increment, membership_number TEXT,first_name TEXT,last_name TEXT,spouse TEXT,phone_priv TEXT,phone_bus TEXT,address_street TEXT,addr_town TEXT,addr_city TEXT,membership TEXT,donor TEXT,1998sa TEXT,1999sa TEXT,2000sa TEXT,200s1 TEXT,2002sa TEXT,2003sa TEXT,2003_reference TEXT,2004 TEXT,2004_reference TEXT,2005 TEXT,2005_reference TEXT,2006 TEXT,2006_reference TEXT, PRIMARY KEY (id),UNIQUE id (id))
Question About Datetime Column In Mysql
i tried this question in the mysql group, but have not heard anything. i have a database with about 20 tables. The some of these tables have datetime type columns in them. What i am basically wondering is if there is a way to make a default value of now() apply if it is not specified when the row is created. i know this is possible with a timestamp, but is it possible with a datetime column ? and if so, how ?
MySQL, Turn Column Into Array
Today is the first time I've used MySQL with PHP. What is the best way to turn a column into an array? This is how I am doing it at the moment, surely this is sub-optimal: $query = 'SELECT something FROM table' $result = mysql_query( $query ); $i = 0; while( $arrayTemp = mysql_fetch_array( $result ) ) { $array[ $i++ ] = $arrayTemp[ 0 ]; } echo "<ul>"; foreach( $array as $string ) { echo "<li>$string</li>"; } echo "</ul>";
Exclude A Column From A Mysql Command
Is there a way to exclude one specific column in a mysql database from a command. IE: I want to use the command $sql = "TRUNCATE TABLE DailyDataSF_copy"; But have it affect all columns except just one specified column that'll stay the same. Any solutions to this? The table has like 90+ columns, which is why I'd like to do it this way if at all possible.
Problem Getting Identical Functions To Work The Same
I have created two functions in a script that are suppose to produce the same results, but the top one doesn't show the page title (the $page_title variable) for some reason. And for the life of me, I can't figure out what I missed. This is especially weird since I just copied the view_page function into the edit_page function w/a few minor changes. Anyway, here's the code: PHP Code:
Searching A Mysql Column Against Multiple Variables
I have an array of zipcodes which I am trying to check against a mysql table. I want to search in the column "zipcode" in a table of a bunch of entries. I want to search each rown to see if the value of the zipcode column is listed within my array. This could be said vis vera, that I want to check the mysql table to see if any of the rows have one of the values from the array inside the zipcode column. I've tried the statement "select * from table where zipcode IN ('$zipsearch')", but it seems to return an odd sequence of data. It doesn't seem thurow enough. similarly the entire statement is : select * from table where description like "%$trimmed%" OR title like "%$trimmed%" AND zipcode IN ('$zipsearch') order by date" I can't seem to get the statemtent to break up my requests right so that the logistics of teh statement are : select from table where (descriptions like variable or title like variable) AND <zipcode search problem>
How To Display Newly Added Mysql Column
I have a mysql table and i want the user to add columns using a php interface and then display the table with the newly added column. I was thinking about putting all the columns names in a special table but there must be another more efficient way. as an example this is my query to display the table: $result = mysql_query("select * from news"); while($r=mysql_fetch_array($result)) { $title=$r["title"]; $message=$r["message"]; //display the row echo "$title <br> $message <br>"; } now if the user alter the table and add a column "rank", how can i update my query automatically so it can display the newly added row (or column)?
MySQL Query Returning Empty Column
Here's my code: $query_get_machine = sprintf("SELECT machines.ID, machines.NotifyID, machines.Name, notify.ID, notify.`Data` FROM machines RIGHT JOIN notify ON machines.notifyID = notify.ID WHERE machines.ID = %s", GetSQLValueString($colname_get_machine, "int")); Can anyone tell why the notify.`Data` column might be returned empty? All others display as they should.
Select Single Column From Mysql Into Array
Is there a way to select a single column from a mysql database and directly put the results into an arrray? Here is the workaround below, but I would like to elimniate the array_push step: $uids=array(); $res = mysql_db_query("db", 'select uid from tbl;', $link); while ($row = mysql_fetch_row($res)) { array_push ($uids, $row[0]); }
MySql VCHAR Column Converted To Float By PHP :-(
I fetch the following value from a string (VCAHR(250))colmun in a MySql table: "30000000000000000000000000000000000000000000000000 0" When I write it out using echo() I get : 3E+50 Appearently the PHP interpreter converts the VCAHR value automatically in a float despite the fact that the value is defined as a VCAHR in MySql. While trying to convert float to string back in PHP using type casting or settype() I get always the string "3E+50". Does someone know how one can fetch the VCHAR as string? Does someone know how to print a formatted float to get the desired result? I tried printf() but no success.
MySql Error 'Unknown Column' From PHP Variable
I'm getting an error message that makes no sense to me. I have a table with a field named 'testkey' for a list of "keys" in the form of ABC10102. I have a php variable holding a specific key number. The relevant code is - $_testkey = 'LAL10102' $sql = "SELECT * FROM `pro_keys` WHERE `keynum`=`$_testkey`"; $result=mysql_query($sql,$db_conn); echoing the $sql gives - SELECT * FROM `pro_keys` WHERE `keynum`=`LAL10102` But I get the following error - MySQL error #1054 - Unknown column 'LAL10102' in 'where clause' ?
Two Identical Class Methods, One Produces Segfault
Consider these two classes. Class Accepter in placement_classes.inc.php works as a form validation object, and it works like a charm: PHP: // placement_classes.inc.php - THIS ONE WORKS! class Accepter { function Accepter() { $this->dbAP =& new DBActionPerformer(); $this->dbAP->connect(); $this->validate(); $this->dbAP->disconnect(); $this->dbAP = null; } /** * Perform validation * * @access private */ function &validate() { // STATIC VOID METHOD foreach ($_POST as $key => $val) if (!isset(${$key})) ${$key} = $val; $varErrArray = array(); array_push($varErrArray, 'placement_name|setMandatory~setMinLength~setMaxLe ngth~setPattern|You must enter a location name~Your location name must be 2 or more characters~Your location name must be 50 or fewer characters in length~^(?!.*<[^>]+> )|Your location name configuration is unrecognizable by our system, please re-enter with legitimate characters|'); array_push($varErrArray, 'unique_key|setMandatory|You must have a unique key prior to posting||'); /*--------------------------------------------------------------------------------------------------------------------- createErrorMsgCollection function from formvalidation.inc standalone function returns an array of ErrorMsgCollection objects -----------------------------------------------------------------------------------------------------------------------*/ $this->errorMsgObjArray =& createErrorMsgCollection($varErrArray); // CREATE FORM OBJECT PASSING ARRAY OF OBJECTS AS PARAMETER $this->formValidator =& new FormValidator('', $this->errorMsgObjArray); $this->isValid = $this->formValidator->isValid(); $this->setErrorArray($this->formValidator->getErrorArray()); $this->formValidator = null; $this->errorMsgObjArray = null; /* if (strcmp(strtolower($action), 'add') == 0 || (strcmp(strtolower($action), 'edit') == 0 && $placement_name !== $origPlacementName)) $this->checkDuplicatePlacement($placement_name); // CHECK FOR DUPLICATE PLACEMENT */ } } This is the class Accepter from contacts_classes.inc.php and while it is now identical in code structure to the Accepter classe in placement_classes.inc.php, whenever this class method is invoked, all processes stop (no errors), arrays are unfinished, objects are unfinished, HTTP never produces, Apache goes down, literally everything crashes! PHP: // contacts_classes.inc.php - THIS ONE PRODUCES A POSSIBLE SEG FAULT! class Accepter { function Accepter() { // NEW 8/17/2004: SURROUND validate() METHOD WITH INSTANTIATION OF $this->dbAP OBJECT PROPERTY $this->dbAP =& new DBActionPerformer(); $this->dbAP->connect(); $this->validate(); $this->dbAP->disconnect(); $this->dbAP = null; } /** * Main method. Will perform all other validation methods and set isValid boolean property * * @access public */ function &validate() { // STATIC VOID METHOD foreach ($_POST as $key => $val) if (!isset(${$key})) ${$key} = $val; $varErrArray = array(); array_push($varErrArray, 'placement_name|setMandatory~setMinLength~setMaxLe ngth~setPattern|You must enter a location name~Your location name must be 2 or more characters~Your location name must be 50 or fewer characters in length~^(?!.*<[^>]+> )|Your location name configuration is unrecognizable by our system, please re-enter with legitimate characters|'); array_push($varErrArray, 'unique_key|setMandatory|You must have a unique key prior to posting||'); /*--------------------------------------------------------------------------------------------------------------------- createErrorMsgCollection function from formvalidation.inc standalone function returns an array of ErrorMsgCollection objects -----------------------------------------------------------------------------------------------------------------------*/ $this->errorMsgObjArray =& createErrorMsgCollection($varErrArray); // CREATE FORM OBJECT PASSING ARRAY OF OBJECTS AS PARAMETER $this->formValidator =& new FormValidator('', $this->errorMsgObjArray); $this->isValid = $this->formValidator->isValid(); $this->setErrorArray($this->formValidator->getErrorArray()); $this->formValidator = null; $this->errorMsgObjArray = null; /* if (strcmp(strtolower($action), 'delete_select') == 0 && @sizeof($delete_selected) == 0) { $this->isValid = false; $this->setErrorArray(array('action' => 'You must select at least one contact for deletion')); } */ } } I've been trying to debug this for days now to no avail. I can verify every object property is present and accounted for (and identical in every way), but if you evoke one it's fine, the other and a segfault!
$_POST Identical Text Fields Into Database
I have a list which is pulled and displayed from my MS Access database. Next to each row, is a text field which appears evertime a new row is displayed and that is called 'code'. I want any text field filled in by the user to be sent into my database, into one field all separated by commas. I have made an attempt at this in the second example script but it needs tweaking. I have here my script which pulls the list from my database: Code:
Valid MySQL Database/table/column Name Regexp
regular expression in PHP which could be used to check that a proposed (My)SQL database/table/column name is valid, i.e. shouldn't result in an SQL error when created? The user of my (hopefully to be opensourced) program has the ability to create database/table/column names on the fly. I'm aware of obvious characters such as ., [space], things like >, etc., which won't work, but haven't been able to source a definitive list, including having googled the MySQL site. Obviously certain characters need to be filtered out, as noted above, but I want to be as unrestrictive as possible; hence just [a-z]* isn't good enough because things like _ are acceptable. Ideally, I'd prefer a regexp that applies to _all_ vendors' databases, not just MySQL as I'm about to migrate the program to being database-independent, probably using PEAR DB, but even a MySQL-specific regexp would do the job. In the longer term, I plan some sort of entity conversion script so that theoretically any character could be used, using some sort of escaping mechanism probably.
Select Count Query, 2 Tables With Identical Structures
I have 2 Tables that have the exact same structures, One is for Inventory, the other is for Relief Inventory (ie. when an item is sold it is moved to relief). What i want to be able to do is to run a query that will count the number of items tested by one person and display that sorted and grouped by the date cleared. I can get this to work when working with just the Inventory table, but the problem is that as items are moved out to relief the counts will change. $query = "SELECT COUNT( * ) AS `Count` , `Date Cleared` , `Tested By` FROM `Inventory` WHERE `Tested By` = ".'"'.$tester.'"'." GROUP BY `Date Cleared` ORDER BY `Date Cleared` DESC "; My question is, how do i run a similar query that will search both tables and combine the results. I have tried adding the other database to the FROM statement, and have been tring to figure out if i can use a join statement but that hasn't yielded any favorable results.
MySQL Query - INSERT - Unknown Column 'test' In 'where Clause'
I have a registration script on my website, and it was working fine, I added a second MySQL INSERT query to it, for another table so I can use JOIN's later on with the second table, but I keep getting the same error: Unknown column 'test' in 'where clause' can someone see whats wrong with this? Code:
How To Query From One Column Then Sort Using Another Column
I am trying to get the last 100 albums I entered into my database using the album_id (Highest being the latest entry) then sort them alphabetically using the album_title column. I can get the latest 100 easily but cannot figure out how to also sort the results by the album_title before I display them. This is what I have so far which gets what I want but not in alphabetical order. <?php $sqlquery = mysql_query("SELECT * FROM albums ORDER BY album_id desc limit 100", $db); while ($result = mysql_fetch_row($sqlquery)) { echo "<a href='music_info.php?album_id=$result[0]'><span style='text-decoration: none'>$result[1]</span><br></a>"; } ?> I have been trying to add a second ORDER BY to the query like so. $sqlquery = mysql_query("SELECT * FROM albums ORDER BY album_id desc limit 100 ORDER BY album_title", $db); but this obviously isn't the way I should be doing it.
|