Jump to content

zq29

Staff Alumni
  • Posts

    2,752
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by zq29

  1. Maybe you could instruct your users to compress their images into a zip archive and have them upload that - You can decompress them with PHP and then loop through the contents. Not exactly user friendly though is it...

    I'm no expert in JavaScript (I'm still picking it up as and when I need it), but does it have file functions? If so, maybe you could use them to select the directory and dynamically create a some pre-filled file input boxes in a hidden div or something?

    Whatever method you choose, you must take maximum file size limits into consideration with PHP, as I think the default limit is set at either 2MiB or 8MiB, unless you have the power to alter this on your server.
  2. I haven't read through your code, but this is how you do it, shouldn't be too hard to understand and integrate into your code:
    [code]<?php
    $orderby = (isset($_GET['orderby'])) ? $_GET['orderby'] : "name";
    $ascdesc = (isset($_GET['ascdesc'])) ? $_GET['ascdesc'] : "ASC";

    $result = mysql_query("SELECT * FROM `table` ORDER BY $orderby $ascdesc") or die(mysql_error());
    //Loop through results etc...

    echo "<a href='?orderby=age&amp;ascdesc=DESC'>ORDER BY DESCENDING AGE</a>";
    echo "<a href='?orderby=name&amp;ascdesc=DESC'>ORDER BY DESCENDING NAME</a>";
    ?>[/code]
  3. This method isn't properly recursive, but it will get what you want I think... [code]<?php
    $handle = opendir("home/user1/cat1/");
    while (false !== ($file = readdir($handle))) {
        echo "$file<br/>";
        if(!strpos($file,".")) {
            echo "<ul>";
            foreach(glob("home/user1/cat1/$file/*.*") as $content) {
                echo "<li>$content</li>";
            }
            echo "</ul>";
        }
    }
    closedir($handle);
    ?>[/code]
    Untested, so you might need to tweak it a bit, but is that the kinda thing you wanted to do?
  4. There is a function called money_format() that should be able to do what you want, although in the PHP manual it says that it is available in PHP versions >= 4.3.0. I'm running 4.3.11 on my development machine and it does not recognise the function, some others are having the same issue by reading the comments section on the manual page.

    If you can get it to work, great, if not, heres a shorter way of doing it than you currently have... [code]<?php
    function ten($number) {
        $length = strlen($number);
        if($length < 10) {
            for($i=0; $i<(10-$length); $i++) {
                $number = "0".$number;
            }
        }
        return $number;
    }

    echo ten(54782); //Prints 0000054782
    ?>[/code]
  5. You can fetch all of a tables data and loop through it with something like: [code]<?php
    $result = mysql_query("SELECT * FROM `table`");
    while($row = mysql_fetch_assoc($result)) {
        //Echo your columns here with $row['name'] to print the column 'name'
    }
    ?>[/code]

    You won't be able to do your second question as easily with PHP - Everything is processed on the server before it is passed to the users browser. You'll have to pass a count to and from your page to keep track of cycles and clicks.
  6. I don't understand why, or how, you want to use arrays to do this, but to create the rows of fields you can just use a simple for() like so: [code]<?php
    $num = 4;
    for($i=0; $i<$num; $i++) {
        echo "<input type='text' name='field_a_$i'/>
        echo "<input type='text' name='field_b_$i'/>
        echo "<input type='text' name='field_c_$i'/>
        echo "<input type='text' name='field_d_$i'/>
        echo "<input type='text' name='field_e_$i'/>
        echo "<input type='text' name='field_f_$i'/>";
    }
    ?>[/code] At this point, you could pass $i as a hidden field to the next script so that you know how many rows you need to loop through. Then its just a case of looping through them: [code]<?php
    $num = $_POST['num'];
    for($i=0; $i<$num; $i++) {
        mysql_query("INSERT INTO `table` (`field_a`,`field_b`....) VALUES ('$_POST[field_a_$i]','$_POST[field_b_$i]'....)") or die(mysql_error());
    }
    ?>[/code] That should be enough of an idea to get you on your way.
  7. This should work...
    [code]<?php
    function return_date($day,$year=2006) {
        $stamp = mktime(0,0,0,1,$day,$year);
        $date = date("jS F Y",$stamp);
        return $date;
    }

    echo return_date(134);
    ?>[/code]
  8. [!--quoteo(post=373148:date=May 11 2006, 02:14 AM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ May 11 2006, 02:14 AM) [snapback]373148[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    Ah cool. So... we all have them, but can only see our own unless we are a mod etc. Cool. Bit paranoid.... never noticed it before. ( and I know I can get a little hot headed at times)
    [/quote]
    You've never noticed it before as that feature was only switched on the other day...
  9. I don't know of any legends for this, but whenever I get an error message that doesn't make much sense to me, I just drop it into Google, somewhere, someone has had the same error and has found out what it means - if it isn't obvious ofcourse.
  10. Not sure if I have gone about this the long way, but this is the idea that first popped into my head...
    [code]<?php
    $needle = "fox";
    $haystack = "The quick brown fox jumps over the lazy dog - What a great fox he is!";
    $replace = "elephant";

    if(strpos($haystack,$needle)) {
        $pos = strpos($haystack,$needle);
        $nlen = strlen($needle);
        $tlen = strlen($haystack);
        $newhaystack = substr($haystack,0,$pos).$replace.substr($haystack,($pos+$nlen),$tlen);
        echo $newhaystack;
    } else {
        echo "$needle not found in $haystack.";
    }
    ?>[/code]
  11. I'm quite sure there are registry enteries for those menu items - Can't remember exactly where they are though. Google should be able to help you out I would have thought.
  12. I think it might be difficult to do this without having a file for each page in each language, because as far as the computer knows, they're all different files regardless if it is the same content be in different languages. You can either store all of your content in their own files, or in a database and pull the correct language out.

    An alternate solution may be to have one copy of each bit of content in a database and dynamicaly submit it to an online translation service and pull the result back and display it. But as we all know, they don't do the best jobs on translation.
×
×
  • 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.