Jump to content

johnc71

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

johnc71's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Ok, I resolved the issue with zero bytes files. So, the final problem I have now is with target directory permisions. If I want to copy file A to folder B, I can't because the folder B rights are set to 755. I tried to chmod the folder B to 777 before copying file, but since the php file is in group "www" I do not have right to chmod folder B. Arghhh... If I ssh to the server and change folder owner to www, am I compromising the security of that folder?
  2. Ok... The file is copied but it ends up with 0 bytes. What gives?
  3. Sorry, I did not mention that the PHP version is 4. I modified your code to make it compatible with 4.0 and although it may not be the cleanest approach, it works. Now the challenge I have is, if the folder name matches but the folder is not writable, how do I get around it? Can I temporarily change the permisions on that folder either via chown or chmod to make it writable and than restore the original permissions? Here is the current code: <?php $indexHtml = 'index.html'; $current_directory = "/usr/local/apache/htdocs/"; $dir_contents = opendir($current_directory); while ($sub_directory = readdir($dir_contents)){ if($sub_directory != "." && $sub_directory != ".."){ if (is_dir($current_directory."/".$sub_directory) && is_writeable($current_directory."/".$sub_directory)){ $directoryName = basename($sub_directory); if(substr($directoryName, 0, 4) === 'demo'){ copy($indexHtml, $sub_directory .DIRECTORY_SEPARATOR. 'index.html'); } } } } closedir($dir_contents); ?>
  4. Can this be done? I want to copy a single file "index.html" to any sub-directory in the current location that begins with "demo". Of course I can do this by running the code below, but how can I do this by using LOOP. so it would be something like this Go thru all sub-directories for each sub-directory where the first four characters of sub-directory == 'demo') { copy index.html to that sub-directory } This is the current non-practical code I have $file = 'index.html'; $dest1 = 'demo/index.html'; $dest2 = 'demoABC/index.html'; $dest3 = 'demo123/index.html'; copy($file, $dest1); copy($file, $dest2); copy($file, $dest3);
  5. I could not modify the post above so I am posting this as edit to make it more clear. If I ran the following: SELECT s.name FROM students s LEFT JOIN enrollment e ON s.student_id = e.student_id WHERE e.class_id != 2 I get the following results: Mary Terry John Mark Isues: Terry should not be listed. Also, Stephanie, James and Irena should be listed. Hope this is more clear.
  6. Thanks for your help. I tried your query but there are still issues. If the student is enrolled in more than 1 class, lets say student #1, he will still show in query results. Also, I would like to get a list of all students who are not enrolled in the particular class, not only the ones listed in the enrollment table. Sorry if this is confusing.
  7. I want to get names of students that are not enrolled in "history" class. When I do the qyery below I get duplicate results. $sql="SELECT FROM students, enrollment WHERE enrollment.class_id NOT IN ('3')";
  8. I have two tables, students and europeans. I would like to get a list of students that ARE NOT europeans. I can get a list of the ones that ARE europeans by doing the following: SELECT * FROM students a, europeans b where a.student_id = b.student_id but how do I get the list of the ones that ARE NOT? It is 2:40AM and my brain is not working anymore. [pre] students +--------------------------+-----------------+ | student_id | student_name | +--------------------------+-----------------+ | 1 | Mark | | 2 | Anna | | 3 | Milos | | 4 | Debby | | 5 | Stan | | 6 | Natasha | +--------------------------+-----------------+ european +--------------------------+-----------------+ | id | student_id | +--------------------------+-----------------+ | 1 | 2 | | 2 | 3 | | 3 | 6 | +--------------------------+-----------------+ [/pre]
  9. I have a DB with pin numbers. Lets say I want to get first 5 pin numbers where the "active" field is set to "yes" and email them to customer. With the code below I will be sending 5 emails but I want to send 1 email with 5 pins. Can someone point me in right direction ? Thanks! $sql1 = mysql_query("SELECT * FROM pins WHERE active='Yes' limit 5") or die mysql_error()); while($r1 = mysql_fetch_assoc($sql1)) { $pin_id = $r1['pin_id']; $pin_number = $r1['pin_number']; @mail($mail_to, $email_subject, $pin_number,$from); }
  10. Ok, I am so tired right now and my brain is not cooperating... what I am trying to do is basically is count number of "type" records in first table and display them just like in table two. I was able to do this by running separate queries for each "type" and using mysql_num_rows to count results but there must be an easier way to do this. I tried Count and Group queries but without success... Any help is greatly appreciated! iduserdatetype 1john2008-08-01pdf 2mary2008-08-02pdf 3mary2008-08-03print 4david2008-08-03ppt 5david2008-08-04pdf 6john2008-08-04print 7david2008-08-05ppt 8mary2008-08-05ppt 9john2008-08-05ppt 10john2008-08-05pdf userprintpdfppt john121 mary111 david[/td][td]12
  11. I tested the code in the previous post and it works fine. However, I would like to know if there is a way to first check if the record already exist in DB before loading data from .DAT file? Basically, I would like to only import new data.
  12. Thanks for your reply. What I am trying to do is, connect to db, update first 4 records where active is "yes" to "no". I am planning to sell pin numbers so lets say I have DB with 100 records. Let's say customer buys 4 pins. I would like to go to DB, retrive first 4 available pins ("Active" = yes) and then set the "Active" field to "No" so that same pins will not be resold. Hope this makes sense.
  13. Your code will set all "active" values to be "no". I edited my original post with more clarifications and exact error I am receiving. Thanks for your help! Here is the exact code: <?php $host="myhost"; $username="myusername"; $password="mypassword"; $db_name="mydatabase"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql1="SELECT * FROM mytable where active='yes'"; $result1=mysql_query($sql1); while($rows1=mysql_fetch_array($result1)){ $count='4'; $id[]=$rows1['id']; for($i=0;$i<$count;$i++){ $sql2="UPDATE mytable SET active='no' WHERE id='$id[$i]'"; $result2=mysql_query($sql2); } } Here is the result: Notice: Undefined offset: 1 in /mycode.php on line 15 Notice: Undefined offset: 2 in /mycode.php on line 15 Notice: Undefined offset: 3 in /mycode.php on line 15 Notice: Undefined offset: 2 in /mycode.php on line 15 Notice: Undefined offset: 3 in /mycode.php on line 15 Notice: Undefined offset: 3 in /mycode.php on line 15
  14. I've tried everything and can't seem to get rid of the annoying "undefined offset" notices. The codedoes what it suppose to do but I would like ot know what I am doing wrong here. I searched for similar posts but can't seem to find the answer for my code. Thanks in advance for your help! $sql1="SELECT * FROM mytable where active='yes'"; $result1=mysql_query($sql1); while($rows1=mysql_fetch_array($result1)){ $count='4'; $id[]=$rows1['id']; for($i=0;$i<$count;$i++){ $sql2="UPDATE mytable SET active='no' WHERE id='$id[$i]'"; $result2=mysql_query($sql2); } }
×
×
  • 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.