Jump to content

spiderwell

Members
  • Posts

    1,008
  • Joined

  • Last visited

Posts posted by spiderwell

  1. a long time ago, on a computer far far away, I used tables for almost all my html layout, especially forms and datagrids (page of database rows/columns).

    Tables however seem to be seen as the devil these days, and css is encouraged with div tags or whatever. however the table is such an obvious thing for forms or datagrids.

    I pretty much dropped tables from my code except for those 2 examples, however i had one day an idea to put everything in lists (mostly because I was mucking around with drag and drop thumbnail lists).

    I find now that a well structured css applied to a <ul> can look just as good if not better than a table equivlent, and if I have anything that I know will warrant that kind of layout will now always opt for that as an alternative to using tables. it also gives me a bonus of allowing drag/drop ordering quite easily.

     

    What are other peoples thoughts on lists vs tables for such layouts?

     

  2. theres always more than one way to skin a cat, here is my effort, I made functions rather than just procedural code. I was thinking of adding a css bit which outputs colored divs to simulate a rainbow, but perhaps later...

    <?php
    //functions
    function startgame(){
    if (isset($_SESSION['rainbow'])) unset($_SESSION['rainbow']);
    $_SESSION['rainbow'] = array("red"=>0,"orange"=>0,"yellow"=>0,"green"=>0,"blue"=>0,"indigo"=>0,"violet"=>0);
    }
    function checkcolor($color){
    if(array_key_exists($color, $_SESSION['rainbow'])){
    if($_SESSION['rainbow'][$color] == 0){
    	$_SESSION['rainbow'][$color] = 1;
    	if(array_sum($_SESSION['rainbow'] ) == 7){
    		return "you have guessed all colors correctly";
    		//you could reset session varialbe here too, to auto reset the game.
    	}
    	else {
    		return "you need " . (7 - array_sum($_SESSION['rainbow'] )) . " more color(s) to finish.";
    	}
    }
    else
    {
    	return "You already chose this color, please try again";
    }
    }
    else
    {
    return "The color " . $color . " is not in the rainbow";
    }
    }
    //runtime
    session_start();
    $output = "";
    if (!isset($_SESSION['rainbow']) || isset($_GET['reset'])){ startgame();}
    if (isset($_POST['color']) && $_POST['color'] <> "") {
    $output = checkcolor($_POST['color']);
    }
    else
    {
    $output = "nothing was entered";
    }
    
    ?>
    <!DOCTYPE HTML>
    <html>
    <head>
    <title>I can see a rainbow</title>
    <style>
    body {font-family:arial;}
    </style>
    </head>
    <body>
    Do you know all the colors in the rainbow?<br><br>
    <?php
    echo $output;
    ?>
    <form name="input" action="rainbow.php" method="POST">
    Color: <input type="text" name="color" value="" >
    <input type="submit" value="Guess!" name ="guess">
    </form> 
    <a href="rainbow.php?reset=1">Start over</a>
    </body>
    </html>
    
    

  3. reading this post, my mind is thinking of an alternative method/solution.

    I might give it ago in the morning (3am here)

    but essentially it involves 1 session object which is an array of keys being the colours and values all being 0 (at start of game), and then update each value to 1 when the colour(session array key) is posted in the form, and of course the usual checks to clarify if its been chosen already or not.

     

    it avoids the maths part at any rate

  4. you would have to create php code to echo out javascript code to do it, this function below is from a site i made (for fun!) and it takes a list form a database, and spits it out in different formats, www.copyandpastelists.com

    if you look i am using the php to write a small javascript array with values from a php dataset from mysql

    you should be able to acheive what you want in this manner, but of course it will need a rewrite to work exactly how you want it too

    function genItem1ListJS($id)
    {
    $i = 0;
    $rtnstr = "";
    $rtnstr .= "<script type=\"text/javascript\">\r\tvar list=new Array(); \r";
    if (is_numeric($id)) //check $id is numeric
    	{
    		$result = DbConnector::query("SELECT * FROM listitems WHERE `listid` = $id ORDER BY `order` ASC;");
    		while ($row = DbConnector::fetchArray($result) ) //list list data
    		{  
    			$rtnstr .= "\tlist[" . $i . "]=\"" . $row['item1'] . "\";\r";
    			$i++;
    		}
    		$rtnstr .= "</script>\r";
    		return $rtnstr;
    	}
    else //$id is not numeric
    	{
    		$this->errors[] = "Value of \$id was not numeric in ListControl->genItem1List()"; //Value not numeric! Add error description to list of errors
    		return false;
    	}
    }
    
    
    

     

    it turns out something like this :

    <script type="text/javascript">
    var list=new Array(); 
    list[0]="Monday";
    list[1]="Tuesday";
    list[2]="Wednesday";
    list[3]="Thursday";
    list[4]="Friday";
    list[5]="Saturday";
    list[6]="Sunday";
    </script>
    
    

  5. This is honestly a great place to start and to keep up with practice. Trying to figure out other people's problems and seeing other's solutions really helped me when I first started learning (hell, it still does help).

    this is how i exercise my php too. solving problems i might not ever come across in my sites that other peeps might do in theirs. i almost always learn as much myself as the person i helped.

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