Jump to content

Cagecrawler

Members
  • Posts

    247
  • Joined

  • Last visited

    Never

Posts posted by Cagecrawler

  1. Don't use w3schools.  The information is quite often out of date (they still list .php3 as a php file extension) or just plain wrong.  If you really want a beginner site like that, I'd recommend Tizag but the first sections of the manual explain the syntax pretty well.

     

    As for the list of other things to learn, xhtml is dead.  Use html5, that's where the standard is going.  Also, ajax is javascript.

     

    The best way to learn is to practice.  Write a script for any problem you have, whether it's organising your music collection or grabbing the latest tweets.

  2. <?php
    $query = mysql_query("SELECT * FROM table ORDER BY datetime ASC");
    $ids = array();
    $startTime = null;
    while ($row = mysql_fetch_assoc($result)) {
    if($startTime == null)
    {
    	$ids[] = $row['id'];
    	$startTime = $row['datetime'];
    }
    else if(strtotime($row['datetime']) - strtotime($lastRow['datetime']) > 60*15)
    {
    	//Within 15 mins of the last row.
    	$ids[] = $row['id'];
    }
    else
    {
    	//Not within 15 mins, so dump the info and start a new row.
    	var_dump($ids,$startTime,$lastRow['datetime']);
    
    	$ids = array();
    	$startTime = null;
    }
    $lastRow = $row;
    }

    Something like this should work.

  3. Something like this should get you started.

    <?php
    $input = "15/09/11 - 18/06/11";
    //Explode input to get first date.
    $dates = explode("-", $input);
    //Explode it again to get the date parts.
    $dateParts = explode("/", $dates[0]);
    //Flip the parts around to Americanise the date, since that's what strtotime takes.
    $time = strtotime($dateParts[1]."/".$dateParts[0]."/".$dateParts[2]);
    //Compare to the current time.
    echo ($time - time() > 60*60*24*30) ? "OVER 30 DAYS" : "UNDER 30 DAYS";

  4. You can work out if it's a multiple by using the modulus operator (%) and then run an if else to compare different multiples.

    $my_no = mt_rand(1, 100);
    if($my_no % 3 == 0)
    {
        echo "<td style=\"background-color:red\">$my_no</td>";
    }
    else if($my_no % 2 == 0)
    {
        echo "<td style=\"background-color:blue\">$my_no</td>";
    }
    else
    {
        echo "<td>$my_no</td>";
    }
    

    Numbers which are both multiples of 3 and 2 (eg. 6) will be coloured red since that comes first in the if else.

  5. You just need to put another for loop around the code that generates the row.

    for($ii = 0; $ii < $number_of_rows; $ii++)
    {
            echo "<tr>";
    for ($i=0; $i<$number_of_columns; $i++)
    {
    	$my_no = mt_rand(1, 100);
    	echo "<td>$my_no</td>";
    }	
    echo "</tr>";
    }
    

  6. You can't close a loop in the middle of the string.  The for loop needs to look like this:

    for ($i = 0; $i < $numItem; $i++) {
       extract($orderedItem[$i]);
       $subTotal += $pd_price * $od_qty;
       $message_c += "<tr class=\"content\"> 
            <td>". $od_qty . " x " . $pd_name ."</td>
            <td align=\"right\">". displayAmount($pd_price). "</td>
            <td align=\"right\">". displayAmount($od_qty * $pd_price). "</td>
        </tr>";
    }
    $message_c += "</table>";

  7. gallery_user needs to be int(11) rather than varchar(20).  It should also be a foreign key with users.id.  When the user logs in, put their id into the session.  Then, when they go to view the images, you can use the following query:

    $query = "SELECT image_id FROM images WHERE gallery_user = '{$_SESSION['user_id']}'";

     

    When you run the query, you can then output the images in a similar manner to your code earlier in the thread. You should also do a check to make sure they're logged in before the query is run (else the session value won't be set).

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