Jump to content

KrisNz

Members
  • Posts

    271
  • Joined

  • Last visited

Posts posted by KrisNz

  1. cool, upon looking up the manual, i see theres actually a function for shuffling a string! So you can replace lines 3 through 6 with

    echo str_shuffle($wordScramble[$randWord]);
    

    Moral of the story - read the manual :)

  2. Does this do the same thing as what you're trying?

    $wordScramble  = array("apple","superman","wireless","midlife","computer","string","massive","wrench","fiber");
    $randWord        = array_rand($wordScramble);
    $word_array      = str_split($wordScramble[$randWord]);
    
    shuffle($word_array);
    
    $scrambled = implode("",$word_array);
    
    echo $scrambled;
    

  3. (to expand on whats already been pointed out)Do it as a csv (comma separated values) . A very basic php5 example would be

    $my_csv_data = "$value1,$value2,$value3";
    file_put_contents("example.csv",$my_csv_data);
    

     

    You should find when you open that file in excel, the values in $value1 etc are in a1,a2,a3 respectively. You can then save that file as an xls if you want. Actually working with an excel object isn't a really realistic option in a web server environment, and in your case not necessary.

     

    you could also check out

    http://www.php.net/manual/en/function.fputcsv.php

    http://www.php.net/manual/en/function.fgetcsv.php

     

  4. Wildbug, that was exactly what I needed. I see now that thats even in the mysql manual for regexp, I just didn't read it thoroughly enough.

     

    I should apologize, when I wrote

    I'm trying to get a count of the number of times an id appears in a record for a particular use
    I realize now this was misleading, what I meant was that I wanted to count rows where the number appeared in that field. I've now been able to do that by working in Wildbug's regexp into my query.

     

    And yes, It would be nice to be able to move those ids into a look up table, but really thats the least of this projects problems!

     

    Thanks heaps to both of you! Really appreciate it.

  5. Hi, I have a column I'm trying to extract information from. The previous developer on a project has stored a number of ids in a text field separated by semicolons. an example of data in this field could be "1;2;3;4" or just "49" if theres only one id. Im trying to get a count of the number of times an id appears in a record for a particular user.

     

    from php im running this query

    select count(ID) as agent_tsr_count from TSR tsr where reaID REGEXP '149[^0-9][[.semicolon.]]{0,1}' and lawID = 31
    

     

    This seems close but is definitely not right! Can someone please advise me on how to change the query so it only matches the whole number, optionally followed by a semi-colon?

     

    Thanks for reading this,

    Kris.

     

  6. If you want to allow multiple files uploaded in one hit you need to add more file elements to your form like

     

    <input type="file" name="form_data[]" size="40">

    <input type="file" name="form_data[]" size="40">

    <input type="file" name="form_data[]" size="40">

     

    see http://au2.php.net/manual/en/features.file-upload.php for a more complete explanation.

     

    You should also make a separate table for storing information about the files since theres often going to be more than one file associated with a lesson plan.

     

    e.g

     

    table : lesson_plan

     

    id

    title

    description

    age_group

    date_added

    email_address

    ----------------------------

    table : lesson_plan_files

     

    id

    lesson_plan_id (foreign key - the id of the record associated with this file)

    file_name

    file_type

    file_size

    file_data

     

     

  7. 1. You've set $_SESSION['first'] after you set the variable $first, so you're trying to set $first to something that doesn't exist yet.

     

    2. The session exists now, you set it on line 4 of page 2.

     

    Note that on page three, you havent POSTed anything to it, you click a link to get to that page so the $_POST array will be empty.

     

    3. Always create things before trying to use them.

  8. you could use strtotime() on their input but not reliably. Rather than have the user type a date in, Id recommend giving the user three select boxes for day, month and year respectively. That will give you a lot more control over the input. Then to make a timestamp you could use for example

    //you should validate that the date they've posted is valid, e.g not 30 february, though mktime will work that out as 1 march i think
    $db_timestamp = mktime(12,0,0,$_POST['month'],$_POST['day'],$_POST['year']); //assuming of course those posted values are integers. 
    

     

  9. nothing to do with php but you want

    <input type="image" src="/path/to/image"/>

     

    you can also ditch "style='margin=0px 0px 0px 0px'"

     

    I'm also curious as to why you'd have a form with only hidden fields.

  10. I had some success with the following...

    $ch = curl_init();
       
        $url ="http://www.php.net/curl_setopt";
    
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
        curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
        
        $result = curl_exec($ch);
        $url_actual = curl_getinfo($ch,CURLINFO_EFFECTIVE_URL);     
        curl_close($ch);
         
                  
    echo ($url_actual); //for me it echo's http://au.php.net/curl_setopt but it will depend your location
    

    I'm not 100% sure this will apply to your situation but give it a go.

  11. It says 'Array' because thats what it is - a variable that can hold a set of values, if you want to see its values you can use print_r() to give you a rough dump of whats in an array or use a loop to go through each value stored in the array. If its multi choice you might be better of with radio buttons so that only one answer can be provided. Heres some basic code you can play around with if you like, try changing type="radio" to type="checkbox" and you'll see that the code still works.

    <html><body>
    
    <?php
    
    //print_r($_POST['answer']); - this gives you a basic dump of what is in the array
    
    //loop through each provided answer
    if(isset($_POST['answer']) and !empty($_POST['answer'])) {
        foreach($_POST['answer'] as $an_answer) {
            echo "The answer You chose was ".$an_answer."<br/>";
        }
    }
    ?>
    
    <form method="post" action="">
    1<input type="radio" name="answer[]" value="1" /><br/>
    2<input type="radio" name="answer[]" value="2" /><br/>
    3<input type="radio" name="answer[]" value="3" /><br/>
    4<input type="radio" name="answer[]" value="4" /><br/>
    <input type="submit"/>
    </form>
    </body></html>
    

     

    Some reference

    http://au.php.net/manual/en/language.types.array.php

    http://au.php.net/manual/en/language.control-structures.php

  12. Yup, whats its doing is setting the 'protected $ID' - a property of the calendar to the value contained in $ID - the first argument of the function. That particular function is what's known as a constructor, and its called automatically when you create an instance of the object.

    E.g

    $cal = new Calendar(1,'2007-01-11'); //I dont know how it expects the date to be formatted so that may not work, its just an example
    echo $cal->ID; //echos '1_' because the constructor has been called and the objects property has been set to 1 and concatenated with an underscore by the constructor
    

    Because that property is marked as protected, it means that its value can only be changed by that class or any class that extends it. So if you tried to go

    $cal->ID = "some crazy value";
    

    You would get an error.

  13. [quote]My question is whether there is a chance that two users would trigger the script at the same time, and the queries that are supposed to run only once every 30 minutes could run twice.[/quote]

    Its unlikely since your code is going to be executed in fractions of a second. If its absolutely imperative that the record is only accessed by one user at a time then you should look in to database transactions, but as redarrow suggested, the simplest solution is to set up a cron job (if you're on a web host there should be a way to do it through the hosts control panel), otherwise this: [url=http://www.faqts.com/knowledge_base/view.phtml/aid/1005]http://www.faqts.com/knowledge_base/view.phtml/aid/1005[/url] might be helpful.
×
×
  • 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.