Jump to content

murfitUK

Members
  • Posts

    207
  • Joined

  • Last visited

Posts 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. 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. 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. 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.

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

  8. 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?

  9. 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!

  10. 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!

  11. 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.

  12. 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.

  13. 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).

  14. 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'

  15. 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:

    We will give x the value of 5Let's print x to prove it. x = 5Now we'll hand over to the function...Inside the function we will give x the value of 10Let's print x to prove it. x = 10Now we'll return to the main program...We have returned from the function. Will x be 5 or 10?Let's print x to find out. x = 5This shows that the value of x wasn't changed in the mainprogram even though we gave it a different value inside the function.
  16. 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.

  17. 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?

  18. 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.

  19. Thanks everyone - using the str_replace works the best.I also found out that the character I wanted is called "middle dot" and has the code & m i d d o t or & # 1 8 3 ;. (Sorry - had to put spaces in between the characters as previewed and found that the codes had been replaced with the little dot!)The function

    str_replace(" ", & # 1 8 3; , $codeSnippet)

    with no quote marks around the & # 1 8 3 ;gives exactly what I need.This·is·what·it·looks·like·with·a·little·middle·dot.HOWEVER...... (life is never easy)Now that there are no spaces it treats it as a big long line of text with no natural breaks for it to start on a new line. This results in a horizontal scrollbar, with just one line of text at the top of the box.I think I will have to count the characters and stick a <br /> after every 40 or so, although not sure if it will work in a textarea. Will soon find out.

  20. Take out the dots before $filenameAdd a " after $filename in the move_uploaded_file lineAmend the quotemarks (I prefer to use double quotes in echo/print lines)The four important lines should now be:$filetmp = $_FILES['userfile']['tmp_name'];$filename = $_FILES['userfile']['name'];move_uploaded_file($filetmp, "images/$filename");echo "Your file is located at <a href='images/$filename'>images/$filename</a>";Now, can someone let me know how to add a line to upload.php so it will only work on .jpg, .JPG, .bmp and .BMP files. Thanks.

×
×
  • Create New...