Jump to content

satre

Members
  • Posts

    29
  • Joined

  • Last visited

Everything posted by satre

  1. Hi All, I have a search page that I've created that looks for artists in my database based on the type of work they do. There are 3 columns: "style, medium, materials" that are created and ordered based on their popularity in my database. I put the count of the number of artists matching these attributes to the right of the radio buttons. I'm wondering if it is possible to update the numbers dynamically based on the choices made by the visitor. For example, If I click "representational" under the style column, of which there are currently 91 artists, is there a way to update the remaining radio buttons based on that choice? That is, change all the numbers to the right of the buttons to reflect how many artists (doing representational work) match the remaining radiobuttons. Some artists do both representational and conceptual work, so after clicking the representational button, the style column would have to keep that button clicked and update the numbers after "abstract" and "conceptual" as well as all the others under the "medium" and "materials" columns too. Then, as I click something under the "medium" column (painting for example), I would keep the buttons clicked and update all the other buttons displaying the number of artists remaining who do both "representational" and "painting" work, and so on... I'm sure it would involve a simple query to mysql to get the numbers, which is no problem, but how do I detect that a button has been clicked and then send the query to mysql and then refresh the page with all the new results? Here's the address for the testing page: http://www.nyartists...searchcount.php I like the radio button design because it lets you see all the possibilities at once. I would like to be able to see how my possiblilites are narrowed by my choices tho'. I'm OK with php and mysql, but I really suck with javascript and other languages, which is probably what I'm going to have to look into I think....?
  2. Hi Folks, I'm thinking this is simple, but just can't seem to figure it out. I use similar code for different tables that works fine, but for this table, it doesn't work so I'm thinking this is a MySQL issue. Here's the code: $sqlmeds = mysql_query("SELECT ALL value FROM test WHERE type like 'media:'"); $meds = mysql_fetch_array($sqlmeds); foreach ($meds as $med){ echo "$med"; } and here is the relevant area of the table with row names "type" and "value" type value . . . media: painting media: works on paper media: collage/assemblage . . . When I run the query to find all 3 values from within phpMyAdmin, no problem, all three are returned, but when I run the exact same query from php, I only get "painting" returned, and oddly, I get an array with two values in it, both of which are "painting". Any ideas??? Thanks!! p.s. I also tried this just in case instead of the foreach, but same result: for ($i=0; isset($meds[$i]); ++$i) { echo "$meds[$i]"; }
  3. Thanks, that's great, however, which command will get the path without me knowing it ahead of time? So sorry, I'm a bit rusty after a long hiatus.
  4. Seems this should be easy, but I'm not finding the solution. Functions like scandir, readdir, and glob that I've been looking at all seem to need me to actually know more about my directory path than I can ahead of time. Here's what I want to do: 1. expand a .tar file (consists of directory, subdirectories, files, and is variable) that I've uploaded to the server 2. look through that expanded directory for a subdirectory named ".pn" -- (note that all my .tar files will have this folder deep in several subdirectories that will be variable in number and have different names depending on the original .tar file) 3. copy the entire contents of the .pn folder to another folder already on my server The hosting company, no doubt, has likely blocked some of the functions I'll need as well, but if someone can point me in the right direction to start, it would be greatly appreciated. Thanks! Satre
  5. Arrgh! I just found it! Sorry for the trouble. You use this: %3F Does anyone know a reference where to find all the character codes for mailto links?
  6. Here's a toughy. Can't seem to find it. I'm trying to simply put a question mark at the end of a question I have in the body of an email generated from a mailto: link. Here's the code: $bodyheader = "Dear $coordinator, could you please forward to Mr. $director? Thanks!%0d ------------------------------------------------------------%0d %0d"; echo "<a href='mailto:$addressee&from=$myemail&subject=subject%20is%20$subject&body= $bodyheader Dear Mr. $director,%0d %0d So, works great except when there is a question mark (as above) in $bodyheader, it won't echo anything past that. If I put in a period (.) all is AOK. I had to use the "%0d" to make a carriage return, anybody know what to put in for a question mark? I already tried the html escape "&#63;" and that does not work. Thanks for your help! -Satre
  7. Oh, duh. My table name is actually "contacts". Works now. Thanks spfoonnewb!
  8. Hi, I hope someone can help me with this... I'm trying to get data from a table and work with it row by row. Here's a snippet of the code: $query = "SELECT program, nickname, city, state, director, directoremail, title, coordinator, coordinatoremail FROM contact"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { echo "Program :{$row['program']} <br>" . "{$row['city']}, {$row['state']} <br>" . "Nickname : {$row['nickname']} <br>" . "Director : Dr. {$row['message']} <br>" . "Coordinator : {$row['title']} {$row['message']} <br><br>"; $myemail = "me@myemail.com"; $director = $row['director']; $coordinatortitle = $row['title']; $coordinator = $row['coordinator']; $programnickname = $row['nickname']; $program = $row['program']; $directoremail = $row['directoremail']; $coordinatoremail = $row['coordinatoremail']; And here's the error I get: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content... on line 33 (the closing bracket for the while statement is further down in the code) Thanks for your help! -Satre
  9. actually, I mean, the value in the table is only a single value, not an array. Isn't there a way just to fetch the single value returned by the query? I used the above workaround because I couldn't find the command to fetch a single value and assign it to a variable.
  10. OK, I feel so dumb. I can't seem to find the answer on the forum or in the php manual. Is there a simple command that can replace fetching an array, can you just fetch the value somehow? $sql = mysql_query("SELECT value FROM settings WHERE name LIKE 'siteurl'"); $sqlfetch = mysql_fetch_array($sql); $rootlocation = $sqlfetch[0]; Thanks! Satre
  11. Here are a couple of nice tutorials. Be sure to read the improvements in the replies at the bottom. http://www.php-mysql-tutorial.com/wikis/php-tutorial/paging-using-php.aspx http://www.evolt.org/node/19340
  12. Yes! That works! Thank you so much! Best, Satre
  13. Hi, I need to have php generate some HTML code for me that needs to be formatted nicely so it can be read easily. Right now, it's just printing every statement without any line breaks so it's just all one big paragraph. The HTML works and looks fine in a browser, it's just hard to read the source code when you want to view the source code. Here's a sample of the relevant php: echo "<!-- BE SURE TO SELECT TAGS: "; if(isset($_POST['Tag_Tesla'])) { $Tag_Tesla = $_POST['Tag_Tesla']; } else { $Tag_Tesla = array(); } $i = 0; //first index while ($i < count($Tag_Tesla)) { echo "Magnet Strength = $Tag_Tesla[$i]"; ++$i; } if(isset($_POST['Tag_Op_System'])) { $Tag_Op_System = $_POST['Tag_Op_System']; } else { $Tag_Op_System = array(); } $i = 0; //first index while ($i < count($Tag_Op_System)) { echo "Operating System = $Tag_Op_System[$i]"; ++$i; } if(isset($_POST['Tag_Age_Class'])) { $Tag_Age_Class = $_POST['Tag_Age_Class']; } else { $Tag_Age_Class = array(); } $i = 0; //first index while ($i < count($Tag_Age_Class)) { echo "Age class = $Tag_Age_Class[$i]"; ++$i; } echo "-->"; echo "<br>"; echo "<!-- BE SURE TO SELECT CATEGORIES: "; if(isset($_POST['Category_MSK'])) { $Category_MSK = $_POST['Category_MSK']; } else { $Category_MSK = array(); } $i = 0; //first index while ($i < count($Category_MSK)) { echo "MSK = $Category_MSK[$i]"; ++$i; } echo "-->"; And here's the format of the HTML source code it gives me (note that it's all squashed together): <!-- BE SURE TO SELECT TAGS: Magnet Strength = 1.5Operating System = 15Age class = Adult--><br><!-- BE SURE TO SELECT CATEGORIES: MSK = shoulder--> I would like it to look like this: <!-- BE SURE TO SELECT TAGS: Magnet Strength = 1.5 Operating System = 15 Age class = Adult--> <!-- BE SURE TO SELECT CATEGORIES: MSK = shoulder--> Any ideas how to do this? Thanks! Satre
  14. OK, thanks! Your suggestion worked: if(isset ($_POST['icd9codes'])) { $icd9codes = $_POST['icd9codes']; echo nl2br("ICD9 Codes = $icd9codes <br />"); What if I wanted to take this variable and break it up into an array of just (words, number, words, number,...)? Would I use explode() for that? That might be easier to put into a table...
  15. Here's ways to handle the errors: $sql0 = mysql_connect('localhost','root','password'); if (!$sql0) { die('Could not connect: ' . mysql_error()); } if (!mysql_select_db('bookstore')) { die('Could no select database: ' . mysql_error()); }
  16. Sorry, code is nothing fancy. Here's the HTML on the form that people will type words followed by a number and then hit return, type more words followed by the associated number and so on: <textarea name="icd9codes" id="icd9codes" cols="70" rows="5"> </textarea> and here is the php code that gets the variable and prints it: if(isset($_POST['icd9codes'])) { $icd9codes = $_POST['icd9codes']; echo "ICD9 Codes = $icd9codes <br />"; } If I type this: blah blah blah, 123 blee blee blee, 456 (with a return after the 123 so I can be on a new line in the HTML text input) it will print out all on one line with a space where I would like a carriage return to be, like so: blah blah blah, 123 blee blee blee, 456 Ideally, I would like to take the input and output it to a table where the words are in the left column, and their associated numbers are in the right column...
  17. I'm sure there's a simple answer to this but I'm just stuck on it... I have a text box in an html form that the user will type several lines similar to this (text and associated number) into: supraspinatus sprain-strain, 840.6 shoulder sprain-strain, 840.9 and when I pass the info to be processed via POST to my php, the variable that represents what was typed in is put all together and prints out like this: supraspinatus sprain-strain, 840.6 shoulder sprain-strain, 840.9 How can I get it to print out as it was entered? Thanks! Satre
  18. This is clunky, and very very slow compared to LOAD DATA LOCAL INFILE, but it works. With my particular file I had to remove 4 spaces in front of some lines so I had to create the temporary text file that was prepped to create the arrays properly. //set and get file names $tempfilename = 'temp.txt'; //delete the previously used temporary file if it exists. Note that the '@' symbol will negate any errors if they exist @unlink($tempfilename); //remove spaces from beginning of GE command-line file and resave $file = $filePath; //uploaded file @chmod($file, 0777); $file_contents = file_get_contents($file); $fh = fopen($file, 'r'); $file_contents = str_replace(' ','',$file_contents); $tempfile = fopen($tempfilename, 'w'); if (!$tempfile) { exit("<p>Unable to open temporary file ($tempfilename) for " . "writing.</p>"); } fwrite($tempfile, $file_contents); fclose($tempfile); chmod($tempfilename, 0777); //erase table in database $sql0 = "DROP TABLE `test`"; $erasetable = mysql_query($sql0); if (!$erasetable) { die('Could not erase table: ' .mysql_error()); } //create table in database $sql1 = " CREATE TABLE IF NOT EXISTS `test` ( `id` int(11) NOT NULL auto_increment, `type` text NOT NULL, `command` text NOT NULL, `value` text NOT NULL, UNIQUE KEY `id` (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1"; $maketable = mysql_query($sql1); if (!$maketable) { die('Could not make table: ' .mysql_error()); } $row = 1; $handle = fopen($tempfilename, "r"); while (($data = fgetcsv($handle, 1000, " ", "\"")) !== FALSE) { $num = count($data); //load data into table $sql2 = "INSERT INTO `test` (`type` , `command` , `value`) VALUES ('$data[0]', '$data[1]', '$data[2]')"; $loaddata = mysql_query($sql2); if (!$loaddata) { die('Could not load data from file into table: ' .mysql_error()); } } fclose($handle); ?>
  19. I'm writing some clunky code based on a loop after fgetcsv or I might try str_getcsv Will post here when I finish, or if someone has a better idea, could they please post?... Thanks! Satre
  20. Hi Everyone, I have some code that works great on our private server, but now that I'm migrating the site over to a public hosting company, I found that they do not allow the use of the command "LOAD DATA LOCAL INFILE" for security reasons. The file I have has over 3000 lines in it (attached). Can anyone suggest a different way to automatically get this data into a MySQL table? (I can't have our secretary signing on to phpMyAdmin and doing everything by hand b/c I need to reduce her labor as much as possible). Here's the code I'm using, and the file is attached. //create table in database $sql1 = " CREATE TABLE IF NOT EXISTS `test` ( `id` int(11) NOT NULL auto_increment, `type` text NOT NULL, `command` text NOT NULL, `value` text NOT NULL, UNIQUE KEY `id` (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1"; $maketable = mysql_query($sql1); if (!$maketable) { die('Could not create table: ' .mysql_error()); } //load data into table $sql2 = "LOAD DATA LOCAL INFILE 'temp.txt' INTO TABLE `test` FIELDS TERMINATED BY ' ' ENCLOSED BY '\"' LINES TERMINATED BY '\\r\\n' (`type` , `command` , `value`)"; $loaddata = mysql_query($sql2); if (!$loaddata) { die('Could not load data from file into table: ' .mysql_error()); } [attachment deleted by admin]
  21. Nothing seemed to work on this. I think the answer may be lying in the construction of the .txt file data itself. I removed the escape and termination parameters and then everything worked. Always getting a MySQL syntax error if I left those parameters in. Here's what worked: $sql = "LOAD DATA LOCAL INFILE 'MR@20Stroke-Trauma@2010.07.txt' INTO TABLE `test` FIELDS TERMINATED BY ' ' ENCLOSED BY '\"' (`type` , `command` , `value`)";
  22. Hi, This is driving me nuts: $sql = "LOAD DATA LOCAL INFILE 'MR@20Stroke-Trauma@2010.07.txt' INTO TABLE `test` FIELDS TERMINATED BY ' ' ENCLOSED BY '\"' ESCAPED BY '\\' LINES TERMINATED BY '\\n'(`type` , `command` , `value`)"; $loaddata = mysql_query($sql); if (!$loaddata) { die('Could not load data into table: ' .mysql_error()); } Gives me an error: 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 '\n'(`type` , `command` , `value`)' at line 1 I've tried all the obvious things I can think of. If I take out the \ in front of \n, I still get an error but it' doesn't include the \n. I tried doing \\r\\n, still have the context error. Anybody have an idea? Can LOAD DATA LOCAL INFILE be used in php? The (unescaped) command works fine when I'm in my phpMyAdmin SQL terminal. Thanks!! Satre
  23. So, I couldn't find any MySQL command to do this, but I ended up pre-processing the file with php as such: $file = 'file/path/name.txt'; $file_contents = file_get_contents($file); $fh = fopen($file, "w"); $file_contents = str_replace(' ','',$file_contents); fwrite($fh, $file_contents); fclose($fh); The trim command never worked, neither in php nor in SQL commands. I think it's because the file is turned into a string, or an array depending on the command you use to read it, but the spaces somehow aren't included in the array? I dunno. No point in dissecting it further for me since this php code will handle it. NB that your permissions have to be set correctly on your file so you can r/w! I wasted an embarrassing amount of time trying to figure out why the file wasn't changing!
  24. Tried the SET command afterwards and TRIM cannot be used here. If I'm reading it correctly, according to the manual, only numeric operations can be done here. LOAD DATA LOCAL INFILE 'set PROTNAME.txt' INTO TABLE `test2` FIELDS TERMINATED BY ' ' ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\n'(`type` , `command` , `value`) SET type TRIM was one example I used, and I tried all variations I could think of after the SET command including setting the 'type' column as a variable and trying to TRIM that, and using the operand "=" between and so on. The code works fine without the SET command, just still have those spaces there. Any other ideas?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.