QuePID
-
Posts
19 -
Joined
-
Last visited
Never
Posts posted by QuePID
-
-
yeah, my bad. teynon is right, the backslash is an escape character, use the forward slash in everything and you should be fine. (I'm not a windows guy, but I think the only time you need backslashes in win is when you're accessing a network path with something like \\server\share)
hope this helps and I'm not saying something really stupid.
Switching to / instead of \ as directory separators worked like a charm.
Thanks guys!
-
$var = 1;
echo "variable is $var"; // should output: variable is 1
echo 'variable is $var'; // should output: variable is $var
* the difference is in the quotes. With double quotes php will check for variables, with single quotes it wont. although your first level ($family) should have worked. I'm not sure how this works on windows though.
in your case, either change the quotes to double, or do something like this that should always work: 'C:\herbariumdb.eku.edu\images\'.$family.'\'.$genus.'\'$species;
hope this helps.
What you suggested worked except for this line (#14):
$speciesname='C:\herbariumdb.eku.edu\images\'.$family.'\'.$genus.'\'.$species;
which gives error:
PHP Parse error: syntax error, unexpected T_STRING in C:\herbariumdb.eku.edu\qpadmin\foldercreationtest.php on line 14
-
what is wrong with what you posted? What is happening when you try to run that code?
Here is the code:
<?php
//Define variables for a test drive of folder detection/creation.
$family="Family";
$genus="Genus";
$species="Species";
//Create variable to hold family name along with path and make the folder should it not exist.
$familyname="C:\herbariumdb.eku.edu\images\$family";
if(!is_dir($familyname)) mkdir ('$familyname',777);
echo "$familyname<br>";
//Create variable to hold genus name along with path and make the folder should it not exist.
$genusname='C:\herbariumdb.eku.edu\images\$family\$genus';
if(!is_dir($genusname)) mkdir ("$genusname",777);
echo "$genusname<br>";
//Create variable to hold genus name along with path and make the folder should it not exist.
$speciesname='C:\herbariumdb.eku.edu\images\$family\$genus\$species';
if(!is_dir($species)) mkdir ("$species",777);
echo "$speciesname<br>";
?>
Here is the output:
C:\herbariumdb.eku.edu\images$family
C:\herbariumdb.eku.edu\images\$family\$genus
C:\herbariumdb.eku.edu\images\$family\$genus\$species
The $vars should be their values not their names, but something is askew.
-
Hi,
I am wanting to check to see if a folder exists, if not create it. PHP on a windows machine so I would like to know how to handle the folder separators. I am wanting to use a path which includes the drive letter, such as... $foldername ="C:\folder1\images\$checkfolder"
I was thinking about using something like this:
if(!is_dir($foldername)) mkdir ("$foldername",777);
What would be the best way of tackling this using windows paths?
-
NULL doesn;t catch empty strings (which your variables are. Empty string and NULL and NOT the same thing.)
Try using empty()
as in
if (empty($date)) $date="0000-00-00";
Worked like a charm!
Thanks.
-
if($var = null) ?
It's not working for some reason here is the code:
if ($date=NULL) $date="0000-00-00";
if ($col_datet=NULL) $col_datet="0000-00-00";
Here is the error given:
Incorrect date value: '' for column 'Col_Datet' at row 1
What I am doing is retrieving a record from a mysql database in which the date and col_datet columns contain either a date or NULL. When I go to update the query with either of those two fields in which they contain a null the update query fails. So what I am wanting to do with PHP is to use a default date of 0000-00-00 instead of a NULL for the update query.
-
How can I check a variable to see if it is NULL and if so set to 0000-00-00?
I've tried:
if ($var IS NULL) THEN $var='0000-00-00'; to no avail.
-
The SET keyword is only use once in an update query statement.
I've tried it with a single SET and still gives the same error.
-
Hi,
I am building an update query which will update a record in a table, but I am getting an error which doesn't make sense to me.
Here is my code:
$query = "UPDATE iknew
SET ID='$id',
SET Herbarium='$herbarium',
SET Taxon='$taxon',
SET Bar_Code='$bar_code',
SET GUID='$guid',
SET Private='$private',
SET Image='$image',
SET Kingdom='$kingdom',
SET Genus='$genus',
SET Species='$species',
SET Variety_Name='$variety_name',
SET Taxon_Author='$taxon_author',
SET Accession='$accession',
SET State='$state',
SET County='$county',
SET Habitat='$habitat',
SET Locality='$locality',
SET Latitude='$latitude',
SET Longitude='$longitude',
SET Quadrangle='$quadrangle',
SET Collector='$collector',
SET Collection_Number='$collection_number',
SET Country='$country',
SET Family='$family',
SET Annotation='$annotation',
SET Col_Date='$col_date',
SET Comments='$comments',
SET Natural_Area='$natural_area',
SET Col_datet='$col_datet',
SET Symbol='$symbol'
WHERE ID='$id' LIMIT 1";
Here is a sample update query:
UPDATE iknew SET ID='62547', SET Herbarium='EKY', SET Taxon='Salix exigua Nutt.', SET Bar_Code='3288', SET GUID='', SET Private='1', SET Image='', SET Kingdom='Plantae', SET Genus='Salix', SET Species='exigua', SET Variety_Name='', SET Taxon_Author='Nutt.', SET Accession='EKY3288', SET State='Kentucky', SET County='Madison', SET Habitat='stream bank', SET Locality='Hagan Mill Road at bridge over Silver Creek.', SET Latitude=' 0', SET Longitude=' 0', SET Quadrangle='', SET Collector='John Hornback', SET Collection_Number='38', SET Country='USA', SET Family='Salicaceae', SET Annotation='', SET Col_Date='1976-04-18', SET Comments='RRP', SET Natural_Area='', SET Col_datet='', SET Symbol='SAEX' WHERE ID='62547' LIMIT 1
And here is the error given:
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 'SET Herbarium='EKY', SET Taxon='Salix exigua Nutt.', SET Bar_Code='3288', SET' at line 3
Any help would be quite appreciated.
-
Using fenway's query with PHP code:
<?php $results = mysql_query("SELECT COUNT(DISTINCT column) AS myCount FROM table"); $values = mysql_fetch_assoc($results); echo $values['myCount']; ?>
Worked like a charm, and was quite fast. How would I do similar for a count of all records within the table?
-
select count( distinct column ) from databasename
When I echo the results of your query string I get "Resource id #6", and when I use mysql_num_rows($results) I get a value of 1 which isn't correct (should be 224). What is the type of data returned in the results of the query?
-
Hi,
I have a database with roughly 73k rows (records). I am using a query string such as:
SELECT DISTINCT Column FROM databasename
I am then using mysql_num_rows($results) to count the number of distinct rows. This method works, but it is slow.
Is there a faster way of doing this perhaps internal to the mysql without having to send the entire results to the PHP when I only need a count?
-
I used phpmyadmin version 3.3.3 to back up MySQL table data and would love to know how to restore the data to mysql via PHP (not phpmyadmin).
Also how can one produce phpmyadmin compatible .sql dumps of a tables data?
I know easy ways of doing this via the mysql command console, but want to be able to handle this via php.
-
I have a large table with roughly thousands of duplicates in a field which should have been unique.
I need a way of creating a new table with all the duplicate records for later sorting.
I have a duplicate-free copy of the old table saved as a new table.
I have tried
CREATE TABLE iknew1 as SELECT iknew.*, COUNT(*) FROM iknew GROUP BY Accession HAVING COUNT(*) > 1
But this only copies one of the duplicated records not both, and I will need both records for comparison and to aid determining if the dupes are from data entry.
-
I am having a problem inserting a record into mysql.
below is my query string:
INSERT INTO iknew (Herbarium, Taxon, Bar_Code, GUID, Private, Image, Kingdom, Genus, Species, Variety_Name, Ssp_Name, Ssp_Varietal_Name, Taxon_Author, Accession, State, County, Habitat, Locality, Latitude, Longitude, Quadrangle, Collector, Collection_Number, Country, Family, Annotation, Col_Datet, Comments, Natural_Area, Col_Datet, Symbol) VALUES (EKY, Lomatium laevigatum (Nutt.) Coult. & Rose, 403113288, eky0812521, 0, eky0812521.jpg, Plantae, Lomatium, laevigatum, var. esculenta, tragei, locii, (Nutt.) Coult. & Rose, 999999, Kentucky, Harlan , Along river bank, between 3500 and 3580 feet of black mountain, 84° 17\' 21\", 37° 34\' 56\", Benham, Ralph L Thompson and Roanld L Jones and Landon McKinney, 2157, USA, Apiaceae, Lomatium spinosa, 09/17/1989, collected cone, Black Mountain Wilderness Area, 09/17/1989, LOLA3)
The error I get is:
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 'laevigatum (Nutt.) Coult. & Rose, 403113288, eky0812521, 0, eky0812521.jpg, Plan' at line 1
Is this because the parenthesis around Nutt. or the & ? I have tried mysql_real_escape_string for every $_POST variable used in the creation of the query string in hopes of adding appropriate backslashes would address the error.
What is causing the error and what solutions can I use to remedy this kind of problem with future insertions?
-
I have a html form with 10 input fields. The user does not have to fill in all ten input forms. The form posts to a php which then assigns the ten $_Post values to 10 local variables that are then used to build a query string.
The building of the query string looks like this: ($maxsearch=1000)
$query = "SELECT * FROM iknew
WHERE Private = 0 AND
Herbarium LIKE '%$searchherbarium%' AND
Genus LIKE '%$searchgenus%' AND
Species LIKE '%$searchspecies%' AND
State LIKE '%$searchstate%' AND
County LIKE '%$searchcounty%' AND
Family LIKE '%$searchfamily%' AND
Locality LIKE '%$searchlocality%' AND
Accession LIKE '%$searchaccession%' AND
Collector LIKE '%$searchcollector%' AND
Symbol LIKE '%$searchsymbol%'
LIMIT $maxsearch";
My echo of the query string looks like this:
SELECT * FROM iknew WHERE Private = 0 AND Herbarium LIKE '%WVA%' AND Genus LIKE '%%' AND Species LIKE '%%' AND State LIKE '%%' AND County LIKE '%%' AND Family LIKE '%%' AND Locality LIKE '%%' AND Accession LIKE '%%' AND Collector LIKE '%%' AND Symbol LIKE '%%' LIMIT 1000
The above query yields 555 results (should yield 772).
whereas the below query yields 772 results (correct)
SELECT * FROM table WHERE Herbarium LIKE '%WVA%' LIMIT 1000
I have been wrapping the variables with %'s as I need some type of pattern match as spelling errors in the input fields is common place.
What is the best way to handle empty input fields with my query string while still using pattern matching?
-
Hi,
I want to display the rows that contain duplicate values within a field of a specific table.
I am currently using the following query:
SELECT iknew.*, COUNT(*) FROM iknew GROUP BY Accession HAVING COUNT(*) > 1
The output of this query only shows one row per found duplicate not every row that contains duplicates (minimum of 2 rows per duplication).
How can I display every single row to which duplication occurs within the field?
-
Hi,
I have the following query to detect dupes:
SELECT tablename.*, COUNT(*) FROM tablename GROUP BY fieldname HAVING COUNT(*) > 1
and I would like to display COUNT(*) via echo in the results output, how do I accomplish this?
I've tried echo "$row[COUNT(*)]"; with no success.
I am basically wanting to display the number of times each field is duplicated. I notice if I use phpmyadmin and run the query it displays a COUNT(*) field that details the repetitions and would like to do the same via my php.
Folder/Subfolder Creation
in PHP Coding Help
Posted
This is very helpful as I desire to produce code which works equally well across platforms.