SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2000
    Location
    Washington, DC
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was looking over the FTP tutorials over at devshed.com and had a question about something that wasn't addressed.

    Is it possible to use a URL of a file and upload it ie. (I forget the exact format) :

    ftp_command(**, destination_file.jpg, http://www.url.com/source_file.jpg, **);

    On a completely different note, I have a couple questions about displaying results pulled from a database.

    1) What is the most efficient way to display results where there are alternating row colors. I am trying to achieve something like phpmyAdmin where it shows odd rows in Gray and even rows in light blue. I have worked out some solutions for this but they don't seem very efficient.

    2) Elsewhere, I would like to display results in three columns. Is there anyway to split the return the results in three evenly distributed columns without making 3 DB queries? I was thinking of having a $count and then doing 3 db queries with:
    query(... LIMIT 0, ($count)/3)
    query(... LIMIT ($count/3)+1, (2*$count)/3)
    query(... LIMIT (2*$count)/3+1, $count)

    Notes: I haven't tried implementing these yet, and I am relatively new to this. I am using PHP4 and mySQL; Is it possible to achieve this with one query?

    Thanks,
    Kurbin
    Don Lair
    GetItCheap.com - Earn cash back online.


  2. #2
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know about the other ones, but here's my answer for 1)...

    1) Put the code inside of a while loop and increment a counter variable at the end of the loop. Then, when you're looking for the color, you can find out if the counter is odd or even and assign a color.

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure about the ftp question but I would assume no.
    To your first question)
    alternating rows

    $row1 = "#cfdafg";
    $row2 = "#ff0000";
    $rowcolor = $row1;
    while ($myrow = mysql_fetch_array($result)) {
    printf'<tr bgcolor="%s"><td>whateverdata</td></tr>', $rowcolor);
    if ($rowcolor == $row1) $rowcolor = $row2;
    elseif ($rowcolor == $row2) $rowcolor = $row1;
    }


    to number 2)
    //Number of columns
    $numcols = 3;
    $count = 1;
    print '<table><tr>';
    while ($row = mysql_fetch_array($result)) {
    if (($count % $numcols) = 0) {
    print '<td>yourdata</td></tr><tr>';
    }
    else {
    print '<td>yourdata</td>';
    }
    $count++;
    }
    print '</tr></table>';

    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    SitePoint Evangelist
    Join Date
    Jul 2000
    Location
    Warwickshire, England
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont think it is possible to use the URL of a file to be retrieved by http.

    1. Re; alternating colours.. I would use the modulus function...

    do {

    $i++;
    if ($i%2 == 0)
    { $colour = "black"; }
    else
    { $colour = "gray"; }

    } while($myrow = mysql_fetch_array ... );

    I would use a similar method to put the results into three columns..

    d'oh.. lots of people beat me to it
    serve me right for reading other forums before typing the reply


  5. #5
    SitePoint Zealot
    Join Date
    Aug 2000
    Location
    Washington, DC
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot, I didn't expect such a prompt response.

    => Freddy, your answer brings up another question I have. I don't really understand the modulus ( % ) math function. Could you please explain it a bit, and it's most common uses?

    Don Lair
    GetItCheap.com - Earn cash back online.


  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    by getting the modulus of an equation you will get the remainder of the division of the two so

    4 % 2 would return 0

    or 5 % 3 would return 2

    so you set a counter to one that increments itself each time the loop is run then you check for the modulus of the counter divided by the number of columns is = 0 if it is you know you are at the end of a row and you can print the <td></td></tr><tr> if not you just need the <td></td>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •