Jump to content

murfitUK

Members
  • Posts

    207
  • Joined

  • Last visited

Everything posted by murfitUK

  1. My brain has gone to sleep and I cannot work out how to write this simple query! Note, this is for mysql. I have a table called `calls` which is used to collect telephone call information. Some of the fields are: `id` `client_id` `date` There are others such as what the call was about, but that's not important right now. I can get the total number of phone calls received during a specified period with the query: SELECT COUNT(*) AS `total` FROM `calls` WHERE `date` BETWEEN '{$rsd}' AND '{$red}' [rsd and red are report start date and report end date] So far, so good. My problem is that I now need to find out how many clients made 1 phone call, how many made 2 calls, how many made 3 calls, etc. I do not need to know which clients called 3 times - just the total number of clients. The output of the query will be displayed something like: 241 clients called 1 time(s) 187 clients called 2 time(s) 45 clients called 3 time(s) 38 clients called 4 time(s) ... etc I've tried many combinations of count, distinct, group by etc but only succeed in getting myself even more confused. I know there is an easy way to do this but I can't find it! If anyone can help I would be very thankful.
  2. Mudsaf is correct that your website host has probably disabled this function. If you can call a script on one of your websites from a different website then it means others can do so to - and you don't want that to happen. You should google for cURL and look at some of the tutorials available. You might be able to do it that way instead, although some hosts disable this as well.
  3. murfitUK

    2 function or 1?

    Will your users know if they are regular or business users before they fill the form in? What if they fill in a business form and then find out they should have filled in the regular form (or the other way round)? To make it easier for your users - and for you - why not have just one form. Some fields will always have to be filled in (name, email etc) and some will be optional and these can all be on the same form. One of the things I have learned since taking up programming and web design is that the best way of starting a project is to get a pen and paper and write down EXACTLY what it is you want to achieve and then the steps you can take to reach it. So the first question you should ask (based on your post) if... why do I need two different forms? If you have no good answer than stick to one.
  4. I'm so glad it turned out to be a php problem and not that I'd forgotten everything I had ever learned! I didn't realise that sin and cos needed radians and not degrees. Interestingly, my apache server returns PI as 0. I have to use M_PI. Don't know why. The succesful result is attached as graph2. The eventual aim is for my users to be able to generate a chart like that attached as example. At the moment they use excel but want the data stored on their client database instead. I have already got the database set up for them to enter the data and now concentrating on creating the results. Thanks everyone. graph2.pdf example.pdf
  5. murfitUK

    Mathematical help

    I am attempting to use php and a pdf creator to generate a chart. It is the mathematical bits I need help with. Basically, the chart has 7 lines (spokes) radiating at equal angles from the centre. <?php// create the pdfinclude ("class.ezpdf.php");$pdf =& new Cezpdf();$pdf -> selectFont("./fonts/Helvetica.afm"); // these value determine the position and size of the graph// (0,0 is the bottom left hand corner of the page)// x1 is the x centre of the graph$x1 = 200;// y1 is the y centre of the graph$y1 = 200;// s is the scalar$s = 100; // create the skeleton of the graphfor ($spoke=1; $spoke<=7; $spoke++) { $angle = ($spoke-1) * (360/7); $x2 = (sin($angle) * $s) + $x1; $y2 = (cos($angle) * $s) + $y1; // draw a line from (x1,y1) to (x2,y2) $pdf -> line($x1, $y1, $x2, $y2); } // output the result$pdf -> ezStream();?> The first spoke works OK but it all goes downhill from there. I have attached the pdf output so you can see what I mean. What makes this worse is that my university degree is in mathematics!!! But it was 30 years ago and I've forgotten everything I ever learned. graph.pdf
  6. After much hair-pulling and gritting of teeth I have finally solved my problem. I realised I wasn't counting sessions properly. I had COUNT(`item`.`desc`) instead of COUNT(*) which was giving incorrect results. The query I've produced is: SELECTCONCAT(`children`.`lastname`, ', ', `children`.`firstname`) AS `Name`,IFNULL(`item`.`desc`, 'Total--->') AS `Activity`,COUNT(*) AS `Sessions`,SUM(`item`.`hours`) AS `Total`FROM`record`, `children`, `item`WHERE`record`.`child_id`=`children`.`id`AND`item`.`record_id`=`record`.`id`AND`record`.`end`='0000-00-00'GROUP BY`Name`,`item`.`desc`WITH ROLLUP This give me the results I expected. However I've just realised that if two children have the exact same name then it will group them both together - the totals will still be correct but it won't differentiate between the two. I will have to include the child id and then use that to group instead of name but that will throw up its own problem because we can't use order by with groupings. So I think it would be easier to ensure we never have two children with the same name!
  7. I need some help setting up a query. There are three tables and the relevant fields are shown below: CHILDREN (id, firstname, lastname)RECORD (id, child_id, startdate, enddate) [enddate will be 0000-00-00 if not yet ended]ITEM (id, record_id, date, desc, hours) Children table might show something like17, Peter, Brown22, Sammy, Watkins Whenever a child is accepted into our service we create a record with the start date and eventually an end date when they leave. The record table will also show their support worker and other info but that's not important right now. Record table might show:6, 22, 2012-02-10, 0000-00-00 [shows Sammy's record starting 10th Feb and still ongoing as no end date]9, 17, 2012-03-25, 0000-00-00 [shows Peter starting on 25th March] Whenever a child undertakes an activity it is entered in the item table.Item table might show1, 9, 2012-03-26, Chess Club, 4.00 [Peter attended chess club for 4 hours]2, 9, 2012-03-28, Theatre Group, 2.00 [Peter - theatre group for 2 hours]3, 9, 2012-04-10, Chess Club, 3.50 [Peter - chess club for 3.5 hours]4, 6, 2012-03-28, Theatre Group, 2.00 [sammy - theatre group for 2 hours]5, 6, 2012-04-05, Music Therapy, 1.50 [sammy - music therapy or 1.5 hours]6, 9, 2012-04-17, Chess Club, 4.00 [Peter - chess club for 4 hours]7, 6, 2012-04-14, Theatre Group, 2.50 [sammy - theatre group for 2.5 hours]8, 6, 2012-04-20, Music Therapy, 1.00 [sammy - music therapy for 1 hour]and so on. Now, I need a list of all activites undertaken by each child with an open record (that is - no end date). My basic query isSELECTCONCAT(`children`.`lastname`, ' ', `children`.`firstname`) AS `name`,`item`.`desc` AS `activity`,`item`.`hours` AS `time`FROM`children`, `record`, `item`WHERE`record`.`child_id`=`children`.`id`AND`item`.`record_id`=`record`.`id`AND`record`.`end`='0000-00-00'ORDER BY `children`.`lastname`, `children`.`firstname` This gives something like:Brown Peter, Chess Club, 4.00Brown Peter, Theatre Group, 2.00Brown Peter, Chess Club, 3.50Brown Peter, Chess Club, 4.00Watkins Sammy, Theatre Group, 2.00Watkins Sammy, Music Therapy, 1.50Watkins Sammy, Theatre Group, 2.50Watkins Sammy, Music Therapy, 1.00 This will do... but I would like to group each child's activities together to count the number of sessions and then the total hours for each activity. So the results will be:Brown Peter, Chess Club, 3, 11.50 [ie he has had three sessions in the chess club totalling 11.5 hours]Brown Peter, Theatre Group, 1, 2.00 [1 session totalling 2 hours etc]Watkins Sammy, Theatre Group, 2, 4.50Watkins Sammy, Music Therapy, 2, 2.50 I'm getting confused with counts, sums and group by statements and would appreciate your help. Ideally I would also like to include some sort of roll up so that I can get Peter showing a total of 4 sessions totalling 13.5 hours and Sammy showing 4 sessions totalling 7 hours but this is not important if it is going to be too difficult.Thanks for your help.
  8. Try this:body { background-image: url('http://img155.imageshack.us/img155/7028/bebop2rc6.jpg'); background-repeat: no-repeat; background-position: bottom right; }
  9. Yes, just put this in your CSS. This example shows how can have different styles for the different input types (text, select, button).input.textual { background-color: #e6ac73; color: #406480; border: 1px solid #ffffff; padding: 3px; font-size: 100%; font-weight: bold; }select.dropdown { background-color: #e6ac73; color: #406480; border: 1px solid #ffffff; padding: 3px; font-size: 100%; font-weight: bold; }textarea { background-color: #e6ac73; color: #406480; border: 1px solid #ffffff; padding: 3px; font-size: 100%; font-weight: bold; }input.button { background-color: #e6ac73; color: #406480; padding: 3px; font-size: 100%; font-weight: bold; }input.check { background-color: #e6ac73; border: 1px solid #ffffff; padding: 3px; font-size: 100%; font-weight: bold; }Then your html will be something like:<input type="text" name="name" class="textual"> for a line of text<input type="checkbox" name="name" class="check"> for a checkbox<input type="submit" name="name" class="button"> for a button<textarea name="name">bbbb</textarea> (don't need to do a class because textarea is defined in the cssand for the drop down list:<select name="name" class="dropdown"> <option value="value">text bit here</option>..</select>You can leave out the class and just have one defined if you want all your inputs to look the same:input { background-color: # etc;}and then you only need your html<input type="text" name="name"> without having to declare the class.
  10. Ah. My local machine is still on 4.0.24, and I don't really want to go about changing things because it was so much trouble getting php, mysql and phpmyadmin all set up originally.The web host company that I use is on 4.1 and I've tried it online - the sub query works just fine.Thanks Vijay, at least I know where the problem lies now.
  11. murfitUK

    IE6 Bug

    I don't get the same problem when I try with IE6. Anyway, it sounds like it could be one of IE's known bugs. Go to the site below and have a look at the guillotine bug.http://www.positioniseverything.net/explorer.html
  12. Hi Vijay - thanks for the reply. Sorry, but I still can't get it to work.This works:SELECT DISTINCT(catID) FROM details; - gives value 1,3,4This works:SELECT kind FROM category WHERE id IN (1,3,4); - gives values Chairs, Clocks, LightingAnd this works:SELECT kind FROM category WHERE id NOT IN(1,3,4); - gives value BedsBut I just can't combine the two without getting an error 1064 - you have an error in your syntaxSELECT kind FROM category WHERE id IN (SELECT DISTINCT(catID) FROM details);What am I doing wrong? I've tried the ` round the field names but still an error. I'm using mySQL - is the above only valid for SQL?
  13. Two tables:1) called "category" with 3 fields: id, kind, description eg0, "Tables", "We have a wide range of tables..."1, "Chairs", "Our large selection of chairs..."etc2) called "details", has numerous fields including one called "type" which has the id from the category table as all products are slotted into a category (so each category could have a large number of products).Trying to do a query to find which categories are not currently used for any products in the details table, but failing miserably. For example, might have in "category":2, "Beds", "All our beds are made from the finest materials..." etcbut if there are no beds in the details table then its an unused category which is what I'm trying to find.I know this should be simple to do but....Please help!
  14. Thanks for the replies - I think the thumbnail page will be the best way forward.After some experimentation I found that if I do <a href="file:pics"> (or file://pics or something like that) it opens a window in IE but not FF. I'll investigate further when I get time!
  15. Hi everyone. I'm back from my holiday in Australia and have put my travel experiences on my website. (If you want to look: websiteI'm creating a disc to send to my mum who has a computer but no internet access (she can't be trusted) and I've made it autorun so she just needs to stick it in the CD drive. The first page will have two options 1) view the website which is saved on disc and 2) open the pics folder so she can browse the photographs.Here's the problem. If I put a link to the pics folder using <a href="pics/"> it opens the folder in the browser with a list of filenames. I really want it to open up the folder as though she had double-clicked her way from the My Computer icon.This is what I mean...I don't want thishttp://www.murfituk.com/pics/no.jpgThis is what I wanthttp://www.murfituk.com/pics/yes.jpgThe reason is that she can then double-click on the first icon and it will open with Microsoft picture viewer which has the next and previous buttons at the bottom, so she can work her way through.Can anyone tell me how to do this? I'm stuck.Thanks.
  16. You can't do it with html alone. You can use html to lay out the form nicely but you then need some sort of scripting language to process the information that has been entered by the user. php is a scripting language although there are others.What should happen when the submit button is clicked is that "form action" calls a new page eg sendmail.php This page then obtains all the information passed to it by the form and carries out the script on the page. Part of this script will check that a valid email address has been entered. If all is OK, the email is sent - but you need your website hosted on a server that is capable of the emailing function as well as being able to run scripts like php.
  17. DELETE FROM tablename WHERE ...... deletes individual rowsTRUNCATE tablename deletes all rows in the table. In some version of sql it also resets any auto increment back to zero. Its equivalent of DROPping the table (ie deleting it completely) and then recreating it. There are difference depending on version of sql/mysql and also some differences depending on the type of database (innodb, myisam).
  18. Or you could use the rand function to generate a random number and use it to create a link. Assuming your pages are called page1.html, page2.html etc:$x = rand(1,5); // generates a random integer number between 1 and 5print "<a href='page{$x}.html'>Random Page</a>"; // sticks the value of x at the end of 'page'
  19. Its because variable defined within a function are usually only available within the function unless you return it to the main program properly. You need to read about global variables at php.net. This is a common cause of problems - you know the variable has a value but not the one you expected.To show how it works run this little script. <?phpprint "We will give x the value of 5<br />";$x=5;print "Let's print x to prove it. x = $x<br />";print "Now we'll hand over to the function...<br />";xtest();print "We have returned from the function. Will x be 5 or 10?<br />";print "Let's print x to find out. x = $x<br />";print "This shows that the value of x wasn't changed in the main<br />";print "program even though we gave it a different value inside the function.";function xtest() { print "Inside the function we will give x the value of 10<br />"; $x=10; print "Let's print x to prove it. x = $x<br />"; print "Now we'll return to the main program...<br />"; }?> Which gives this output:
  20. You have a : at the end of $host='' instead of ;If that doesn't fix it try troubleshooting one bit at a time.After the require function try printing out the variables egprint $host . "<br />";print $user . "<br />";print $passwd;exit;Just to make sure that the variables have been defined. Is mysql.php in the same folder as the main file? Maybe you have to navigate to a different folder eg require '../mysql.php'.Try the : / ; first then take it from there.
  21. murfitUK

    TOP TIPS

    EDIT: Please read entire topic. Important conclusion at the end.Might I suggest a "Top Tips" page for each subject. Lots of little things that the more experienced members have come across. Not huge amounts of text - that would be a tutorial - but just a couple of sentences.For example, today I had a problem that took me hours to solve and if I'd been thinking straight the solution would have been obvious.I had created a webpage to insert text into a mysql database. It took the text, added slashes for quote marks and other special character and so on. Another page pulled the text from the database and displayed it. All this was done on my computer. It worked fine.When I uploaded to my IP provider server it didn't work. I tore my hair out trying to figure out what was going on. It was displaying lots of slashes where they shouldn't have been. I changed this, changed that, changed everything until I had lost track of what I'd done.The solution - I should have run phpinfo(); on my local server and the IP's server. I would have found that my local server had "Magic Quotes - Off" but my IP's server had "Magic Quotes - On". So I switched my Magic Quotes on, made a couple of changes, uploaded everything again and it worked.Obviously, my IP's server is beyond my control and they might switch Magic Quotes off tomorrow if they felt like it, in which case everything would start to go wrong again. But at least I would know where to start.So my Top Tip would be something like "PHP/mySql: If slashes and/or quote marks start appearing or disappearing without reason why not check phpinfo() - are Magic Quotes On or Off? It makes a difference."Most of us on these boards will have, at some time or another, come across problems that caused us hours of headaches and stress - but turned out to be simple to fix. Maybe if there was a single page to look at, with just a line or two for each issue, it might save others a lot of hassle, and promote sharing of experience and good practice.I'm aware that lots of (most?) people don't read tutorials or search properly before posting their problems anyway so it might all be a waste of time. Is it worth doing? What do you all think?
  22. I use this:http://www.ros.co.nz/pdf/It looked complicated at first but it only took a couple of minutes to get it working.
  23. You can use css to create a 3 column page. The left column can hold the links, the right column some other stuff and the middle column (the largest) the main content.There is an easy tutorial - have a look at Selectutorial here:http://css.maxdesign.com.au/selectutorial/tutorial_intro.htmscroll down and click on the finished sample button to see what it looks like - I think its what you want.
  24. Thanks justsomeguy - knew you would know the answer to that one! It's all working now.
  25. Hi everyone.I'm trying out some of the functions to create thumbnail images and the code calls functions such as imagecreatetruecolor and getimagesize. This results in the error message about call to undefined functions.I know I've got to change something in my php.ini file but I've no idea what. Any pointers?Thanks.
×
×
  • Create New...