Jump to content

c_pattle

Members
  • Posts

    295
  • Joined

  • Last visited

Posts posted by c_pattle

  1. Thanks.  Yeah that should work but what I want to do is to perform a different count for each criteria.  So the final result set will have seperate count for when the status is "sick" and a seperate one where the status is "late".  Is this possible?

     

    Thanks

  2. Thanks for your help.  I understand it now.  Sorry another question.  Is it also possible to perform a count on the same field but using a different condition?  What I also want to do is to count the number of times h.status="late". 

     

    Would I be able to do this in the same query because I'm already performing a count on this field?

  3. I have a table called "staff" which has a list of employees details.  I also have a table called hours which stores employee hours. 

     

    What I want to do is the have a query that selects all the fields from the staff table such as

     

    SELECT * FROM staff WHERE username="jbloggs"

     

    and also to select the number of times this employee has called in sick such as

     

    SELECT COUNT(status) FROM hours WHERE status="sick" and username="jbloggs"

     

    Is there an easy way to merge these two sql queries into one?

     

    Thanks for any help

  4. I have a form that has lots of fields and lots of submit buttons.  The PHP that I am using at the moment if one of these submit buttons has been pressed is

     

    if(($_POST['submit1']) || ($_POST['submit2']) || ($_POST['submit3']).....
    

     

    As there are about 30 of these submit buttons it means that there is a lot of code.  Is there an easier way to do this? 

     

    Is there a way to have a condition such you can check if a submit button between "submit1" and "submit30" has been pressed?

     

    Thanks for any help. 

  5. So for example in this example the output I'd want would be

     

    username

    date

    clock in

    clock out

    number of days (holiday)

    jbloggs

    2011-07-01

    08:53:15

    17:00:04

    2

    jbloggs

    2011-07-02

    08:52:42

    17:00:09

    2

     

    The results would show all of the records from the "hours" table with the number of days holiday from the holiday table that they have that month. 

  6. I have two tables called "hours" and "holiday".  One records employees hours and the other records any holidays they have booked.  What I want to do is to have a mysql query that will select all of the records in the "hours" table for "jbloggs" and then select from the "holiday" table any holidays that "jbloggs" has that month.  If I was to do this as two separate sql queries it would be,

     

    select * from hours where username="jblogg"

     

    and

     

    SELECT number_of_days FROM holiday WHERE username="jbloggs" AND holiday.date_start >= '2011-07-01' and holiday.date_start < date_add('2011-07-01',interval 1 month)

     

    So the result set I want is to have all of the hours printed out and on each row the number of days holiday for that month which in this case would be 2.  I tried using a join but I kept getting lots of rows in the hours table repeated.  Is there anyway to do it so that row won't be repeated?

     

    Below are what the tables might look like. 

     

    Hours table

     

    username

    date

    clock_in

    clock_out

    jbloggs

    2011-07-01

    08:53:15

    17:00:04

    jbloggs

    2011-07-02

    08:52:42

    17:00:09

     

    Holiday table

    username

    date_start

    number_of_days

    jbloggs

    2011-07-25

    2

    jbloggs

    2011-08-11

    5

     

    Thanks for any help!

     

  7. I have a variable that stored the date

     

    $date = date("Y-m-d");

     

    If I want to deduct or add days to this so I get a date in the past or future is there an easy way to do this or do I have to convert it to a timestamp then convert it back etc?

  8. What I want to achieve is that I have to text string and I just want to append the word "and" to them both at the same point in my program.  However I don't want them to be linked because they will be different string.  I just thought it might be more efficient and it will save on code if I could append "and" to them both at the same time. 

  9. I'm trying to give two variables the same value which I know you can do with the following

     

    $variable1 = $variable2 = "value";

     

    However I want to concatenate this value to two variables.  However if I use the code below it also concatenates the value in $variable2 to $variable1. 

     

    $variable1 .= $variable2 .= "value";

     

    Is there a way to make the above work?  I'm just thinking it will save me some lines of code. 

  10. At the moment I'm learning OOP programming in PHP but I was surprised at the lack of built-in methods compared to other languages?  In Python you have built-ins such as the __str__ method but in PHP all I've come across are the __autoload, __construct and __destruct.  I am missing some or is that all there is?

  11. I have the following in my .htaccess file. 

     

    RewriteEngine on

    Options -Indexes

     

    #Re-write rules

    RewriteRule ^/([A-Za-z0-9]+)$ $1.php

    RewriteRule colour/([A-Za-z0-9]+)$ index.php?colour=$1

    RewriteRule article/([0-9]+)$ article.php?number=$1

     

    My first two rewrite rules work but the last one doesn't.  I want the url - article.php?number=1 - to be replaced with - article/1.  At the moment the redirect still takes me to the article.php page but the "number" variable seems to not be defined. 

     

    Thanks for any help. 

  12. Recently I've started learning Python and although I think it's a great language I'm not sure if it as good as PHP for web programming?  With PHP you can embed it into your HTML pages but as far as I'm aware you can't do this in python. Therefore do most people who create python scripts that writes all of the HTML instead?  I'm just wondering if anyone could let me know if they use Python for web development and how they go about doing it?

  13. I'm trying to use mod_rewrite to rewrite my urls.  At the moment the url I want to rewrite is

     

    http://localhost/web/index.php?colour=red

     

    and I want to change it to

     

    http://localhost/web/colour/red

     

    I've uploaded a .htaccess file to the "web" directory but I keep getting a 404 error page.  I've included the contents of my .htaccess file below. 

     

    RewriteEngine on

    RewriteRule ^/colour/([A-Za-z0-9]+)$ /?colour=$1

     

     

    Thanks for any help

  14. I've just enable mod_rewrite and tested it's all working fine and now I want to put it in actions.  I have a page called "review.php" that takes a review id which is a number.  So for example the url might be "review.php?review=123".  I want to change this so the url would be "review/123/" however I'm having some trouble with my rewrite rule. 

     

    RewriteEngine on

    RewriteRule ^review/([0-9]+)/?$ review.php?review=$1

     

    When I type in "review/123/" I get taken to the review.php page but the review parameter doesn't seem to work.  Also when I get to the review.php page all of the css has been displayed.  Does anyone know why this is happened?

     

    Thanks for any help. 

  15. Whenever try to use the PHP mail function on my local server it also fails but then when I upload my scripts to my webspace they work fine.  I think there must be something wrong with my php.ini file.  Below I have copied the mail function section of my php.ini file. 

     

    [mail function]

    ; For Win32 only.

    SMTP = localhost

    smtp_port = 25

     

    ; For Win32 only.

    ;sendmail_from = me@example.com

     

    ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").

    sendmail_path = sendmail -t -i

     

    ; Force the addition of the specified parameters to be passed as extra parameters

    ; to the sendmail binary. These parameters will always replace the value of

    ; the 5th parameter to mail(), even in safe mode.

    ;mail.force_extra_parameters =

     

     

    Thanks for any help. 

  16. I'm using PHP and MySQL to do a full text search but I was wondering if there is a way to make it work for words that are only 3 characters long?  At the moment I have MySQL configured so that it only returns results for words of 5 characters or longer but I need it to work for 3 character words. 

     

    Thanks for any help. 

  17. I have a form that allows users to submit content to my site.  When they submit content they sometimes enter characters such as £ and &.  This means that when I fetch this data from the database my html won't validate.  Is there an easy way to replace all these characters with the proper codes such as £ and &?

     

    Thanks for any help. 

×
×
  • 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.