Jump to content

GingerRobot

Staff Alumni
  • Posts

    4,082
  • Joined

  • Last visited

Everything posted by GingerRobot

  1. Well, i've learnt most of what i know from these forums! Seriously, i've learnt so much from looking at other people's problems and other people giving solutions.
  2. Indeed. A google search confirms thats the problem, and you can get round it by using imagecreatetruecolor() rather than imagecreate().
  3. Well, with a quick test of moving the call to imagecolorallocate() outside the loop, it appears that there might be a limit on the number of times you can allocate a colour. I've looked at using imagecolordeallocate(), but i can't get it to work.
  4. Well, as it says, the argument you passed to the mysql_query() fuction is not a valid link resource. Therefore, something has gone wrong with your connection to the database. Do you have any error checking in config.php?(which i presume contains the database connection?) Also, the link parameter is actually optional. You might not need it anyway.
  5. I have to wonder, it what way is an incorrect opening tag "advanced php"?
  6. True, though i personally avoid using the mktime function on principle. I dont know of another function where the parameter order is so completely unintuitive!
  7. You need to first convert your date into a timestamp, then take off the required number of seconds, then convert your timestamp back to whatever format you wanted. Try: <?php $date = '2007-10-05'; $timestamp = strtotime($date); $new_timestamp = $timestamp - 60*60*24*5; $new_date = date('Y-m-d',$new_timestamp); echo $new_date; ?>
  8. Hmm, just a thought...couldn't you explode by the space, then deal with each word individually? If the first character of the word is an apostrophe, you'll want to make the next character uppercase? <?php $str = "how 'bout it?"; $words = explode(' ',$str); foreach($words as $k =>$v){ if($v[0]== "'"){ $words[$k][1] = strtoupper($v[1]); } } $str = implode(' ',$words); echo $str; ?>
  9. The $country variable comes from the previous form selection, probably stored in a session. The process would be something similar to: 1.) User first navigates to your page, and selects a country 2.) They submit the form 3.) You set the county in a session variable, pull all of the states/regions for the selected country from the database, and display a select box with this information in 4.) The user selects a state/region and submits the form 5.) You then do whatever you wanted to do with the state and country - you can get the selected state from the form submission, and the country from the session variable. Im not sure if that clarfies the problem or not; im not 100% sure what the issue is - hope it helps though.
  10. Why dont you just use links rather than submit buttons? You can then pass the id in the URL. The reason why you always seem to get the ID of the last item is that all of your hidden fields have the name 'id', hence when you retrieve the value from the GET/POST array, its always the last one. Edit: If you particularly want to use submit buttons, i suggest you use a bit of javascript to update the value of a single hidden field prior to form submission.
  11. As was said, you only select those states from the database which are from the previously selected country. That is the idea of the where clause in this statement: $sql = "SELECT * FROM some_table WHERE country = '$country'";
  12. Erm, i hate to say it but you're rather re-inventing the wheel with your function. Try the htmlentities() function.
  13. Surely if you ask 100 customers 10 questions each, then the total number of questions asked is 1000. If overall 300 questions were answered with a yes, then you need to work out the percentage that 300 is of 1000: <?php $customers = 100; $questions = 10; $total_questions = $customers * $questions; $positive_answers = 300; $percentage = $positive_answers/$total_questions *100; ?>
  14. Unless ive missed something, you first need to find all the of the words that have been underlined. You then need to search your database for their definitions. Only after doing this can you do the replacement. I would do something like: <?php $string= 'The <u>text</u> that contains <u>all</u> the underlined links'; preg_match_all('|<u>(.*?)</u>|',$string,$matches);//find all the underlined links $words = $matches[1];//an array of all the words to look up $original = $matches[0];//an array of all the original text we will replace later //sort the array - allows us to select all results from the db in one query - we also order the query by the words so we can match them up sort($original); $sql = mysql_query("SELECT `definition` FROM `yourtable` WHERE `word` IN ".implode('\'',$words)." ORDER BY `word`");//select all of the words we want, ordering their definition by the word $definitions = array(); while($row = mysql_fetch_assoc($sql)){//create an array of all the definitions $definitions[] = "<span class='link'><a href='javascript: void(0)'>".$row['definition']."<span>popup text goes here</span></a></span>"; } $string = str_replace($original,$replacement,$string);//do the replacement ?>
  15. It certainly seems like overkill to have 3 sizes to me. Personally, i think the current medium sized images could afford to be larger. You could then certainly get rid of the largest size.
  16. Turns out i was missing something simple. Didn't notice the two negative signs. Whoops.
  17. Well i for one am confused about your code. If you are retrieving images that are stored in the database, why do you get the name from the $_POST array? And secondly, i think you should take a look at the idea of database normalization: http://en.wikipedia.org/wiki/Database_normalization You would be better having a seprate table that stores the image names, which is linked to your employees table by an employee id.
  18. No problem. I already had half of it done for something else anyway.
  19. Well, here's a rough and ready example: <?php function speedo($speed){//takes a speed from 0-100 $image = imagecreatefromgif('phpfreaks.gif'); $black = ImageColorAllocate($image,0,0,0); $max_rotation = 300;//the number of degrees to max speed from original $rotation = $max_rotation/100*$speed;//calc the rotation from 0-300 based on speed from 0-100 $center = 40;//center of picture is 40px in $start = array(40,40);//start of line $end = array(-20,30);//end of line $end = calc_rotate($rotation,$end);//calc co-ordinates after rotation //add center value to make co-ordinates relative to picture $end[0] = $end[0] + $center; $end[1] = $end[1] + $center; imagesetthickness($image,3); imageline($image,$start[0],$start[1],$end[0],$end[1],$black); header('Content-type: image/png'); imagepng($image); imagedestroy($image); } function calc_rotate($angle,$points){//takes an angle and the x,y co-ordinates. Returns new co-ordinates //[m1 m2] * [$points[0]] //[m3 m4] [$points[1]] $m1 = cos(deg2rad($angle)); $m2 = -sin(deg2rad($angle)); $m3 = sin(deg2rad($angle)); $m4 = cos(deg2rad($angle)); $temp0 = $points[0] * $m1 + $points[1] * $m2; $temp1 = $points[0] * $m3 + $points[1] * $m4; $points = array($temp0,$temp1); return($points); } speedo(50); ?> Which takes a speed from 0-100 and moves the pointer based on that. I say rough and ready because the image isn't perfect - im not sure the dial is quite centered, so the pointer sometimes stretches too far. Uses the image attached. [attachment deleted by admin]
  20. Well, personally id change the picture so that the copy you have saved includes all put the 'pointer'. You could then change the position of the pointer depending on the speed. I think the easiest way to draw the pointer on would be to imagine it as a straight line between two co-ordinates. You take the middle of the speedo as (0,0), and work out the position relative to that for the end of the pointer at speed 0. For example, it might be (-20,30) as a bit of a guess. You could then multiply your co-ordinates by a matrix to produce a rotation. If you multiply your 1x2 co-ordinate matrix by the 2x2 matrix: cos x -sin x sin x cos x You'll get a rotation of x degrees anticlockwise.You'll want clockwise rotations, so make x negative. If you've not done the maths before, take a look at: http://en.wikipedia.org/wiki/Matrix_multiplication & http://en.wikipedia.org/wiki/Transformation_matrix You'll then need to change the co-ordinates to points on your image. Might sound like a lot of work, but its quite straightforward.
  21. Indeed. The only reason why people end with the extension .inc.php is to show that the file is one that will be included by others. Some people simply end with the extension .inc. However this is bad practice and a security issue, because it may lead people to be able to see the php code in plain text. As for resticting access, it may not be necessary. As long as the final extension is .php, then the page will be parsed by the php processor, so no-one would be able to see your code. If access is still an issue, then as has been suggested, you can restrict with permissions or .htaccess. Another alternative is to place the files outside of the web root folder.
  22. The second parameter of the date() function is a timestamp. A timestamp is a number in seconds which is the time that has passed since the unix epoch (1/1/1970). Therefore, to change the the format of the date, you would first need to convert the date time field you have to a timestamp, either with the strtotime() function, or with the mysql UNIX_TIMESTAMP() function. However, the mysql DATE_FORMAT() function will take a date time string as its value. This is probably your best option: <?php $sql = "SELECT DATE_FORMAT( `yourfield` , '%y %c %e' ) FROM `yourtable`"; $result = mysql_query($sql) or die(mysql_error()); ?>
  23. Well thats rather freaky. Went to 6th form today and we were looking at this exact sort of problem in maths! Turns out one solution would be to use the Hungarian Algorithm. Not sure how easy it's going to be to make php do this, but im sure its possible.
×
×
  • 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.