Jump to content

chriscloyd

Members
  • Posts

    488
  • Joined

  • Last visited

Posts posted by chriscloyd

  1. If anyone is learning how to code, and does not have hosting.  I would be willing to set them up some free hosting.  PM me!

    I have 10gs with Unlimited bandwidth. Cpanel, email, and mysql

  2. Seems to be working fine for me...

    http://codetut.com/projects/switch.php

    I am guessing you are trying to pass in a variable so it switches cases?

    if so I added some code for you

    you can try it like this

    http://codetut.com/projects/switch.php?team=redwings

     

    here is the code now

    <html>
    <head>
        <title>Favorite Original Six Hockey Team</title>
    </head>
    <body>
    <h1>Original Six </h1>
    <?php
    $t = date("H");
    
    if ($t < "10")
    {
        echo "Good morning!";
    }
    else if ($t<"20")
    {
        echo "Good afternoon!";
    }
    else
    {
        echo "Good evening!";
    }
    ?> <br> <br>
    
    <?php
    $favhockeyteam = isset($_GET['team']) ? $_GET['team'] : "";
    switch ($favhockeyteam)
    {
        case "blackhawks":
            echo "Your favorite hockey team is blackhawks!";
            break;
        case "redwings":
            echo "Your favorite hockey team is redwings!";
            break;
        case "bruins":
            echo "Your favorite hockey team is bruins!";
            break;
        case "canadians":
            echo "Your favorite hockey team is canadians!";
            break;
        case "maple leafs":
            echo "Your favorite hockey team is maple leafs!";
            break;
        case "rangers":
            echo "Your favorite hockey team is rangers!";
            break;
        default:
            echo "Your favorite color is neither red, blue, or green!";
    
    }
    ?> <br> <br>
    
    </body>
    </html>
    
  3. How can you read your structure... :P

    $delid = isset($_GET['del_id']) ? $_GET['del_id'] : '';
    
    if($delid > 0 && (is_array($trade_toonid) && sizeof($trade_toonid) > 0)){
    
         if($delid > 0){
    
              $user_toons = implode(",", $trade_toonid);
    
              $update_ctoons = "update tbl_users_ctoons set location=1 where trade_id={$delid} and usrctoon_id in ($user_toons)";
    
              $del = new database();
    
              $del->myquery($update_ctoons,1);
    
              $del_trade = "delete from tbl_trade where trade_id={$delid}";
    
              $del = new database();
    
              $del->myquery($del_trade,1);
    
              $del = new database();
    
              $del->where("trade_id={$delid}");
    
              $del->delete("tbl_trade");
    
              header("Location: manage_tradeboard.php");
    
              //exit();
    
         }
    
    }
    
  4. You have to create your own sort function, and use usort on the array

    $array = array();
    
    foreach ($xml->children() as $child) {
         $array[] = array('Name' => $child->Name,
                          'Date' => $child->Date);
    }
    
    function sortArrayByDate($a, $b){
         return strtotime($a['Date']) - strtotime($b['Date']);
    }
    
    usort($array, "sortArrayByDate");
  5. while($row = mysql_fetch_assoc($sql)){
         extract($row); //you are calling extract, but your not using it...
         //in you <img you should have an alt always.
         //that tells the google spider what the image is
         echo <<<EOT
         <tr>
          <td style="text-align: center;">
           <img height="100" width="100" src="Images/Products/{$prod_photo}" alt="{$prod_name}" />
          </td>
          <td style="text-align: center;">
           {$prod_name}
          </td>
          <td style="text-align: center;">
           {$prod_brand}
          </td>
          <td>
           <form name="price" method="post" action="ret_addprod.php">
            <input type="hidden" name="prod_id" value="{$prod_id}" />
            <input type="text" name="prod_price" />
            <input type="submit" value="Add" />
           </form>
          </td>
         </tr>
    EOT;
    }
    

    I just cleaned it up a little bit and threw in the hidden value, and used the extract function

  6. You could even make it more fancy and if a product price didnt update you can pass numbers through the session insertsuccess like 0 if it does not fail and the prod_id if it fails so you can put and error next to the one that had the problem updating.... if you do not understand let me show you

    your script

    <?php 
    
    
    session_start(); 
    
    
    include('db_connect.php'); 
    
    $username = $_SESSION['username']; 
    
    $prod_price = mysql_real_escape_string($_POST['prod_price']); 
    
    $prod_id = mysql_real_escape_string($_POST['prod_id']);
    
    $url = 'retprod.php'; 
    
    $user = mysql_fetch_assoc(mysql_query("select user_id from tbllogin where username = '{$username}'"));
    
    $insert = mysql_query("insert into tblretprod (user_id, prod_id, prod_price) values ('{$user[user_id]}', '{$prod_id}', '{$prod_price}')"); 
    
    if($insert){
    
         $_SESSION['INSERTSUCCESS'] = 0;
    
    }
    else{
    
         $_SESSION['INSERTSUCCESS'] = $prod_id;
    
    }
    
    header("Location: /" . $url);
    
    ?>
    

    your form

    <?php
    
    //you can also make it that if the price is already set it overrides this one....
    //I used sample id's
    ?>
    <form action='' method='post'>
    {Product Info Here}
    <input type="text" name="prod_price" value="" />
    <input type="hidden" name="prod_id" value="37498" />
    <input type="submit" name="prod_submit" value="add" />
    <?php
    if($_SESSION['INSERTSUCCESS'] == '37498'){
        echo 'Error Updating Price!';
    }
    ?>
    
  7. You are selecting one product from tblproduct and you keep re-entering the same prod_id.  What you need to do is on your form make a hidden value with the products id

    <?php 
    
    
    session_start(); 
    
    
    include('db_connect.php'); 
    
    $username = $_SESSION['username']; 
    
    $prod_price = mysql_real_escape_string($_POST['prod_price']); 
    
    $prod_id = mysql_real_escape_string($_POST['prod_id']);
    
    $url = 'retprod.php'; 
    
    $user = mysql_fetch_assoc(mysql_query("select user_id from tbllogin where username = '{$username}'"));
    
    $insert = mysql_query("insert into tblretprod (user_id, prod_id, prod_price) values ('{$user[user_id]}', '{$prod_id}', '{$prod_price}')"); 
    
    if($insert){
    
         $_SESSION['INSERTSUCCESS'] = true;
    
    }
    else{
    
         $_SESSION['INSERTSUCCESS'] = false;
    
    }
    
    header("Location: /" . $url);
    
    ?>
    
  8. I have created the functions to show you how, but I do not know what you are wanting with some of the code.

    This code is where I am unclear because I do not know where you are getting $extra from

    $count = count($extra);
    	// If no errors, display the form data
    	if($errors == "")
    	{
    echo <<<END
    	<p>$first_name $last_name thank you for your interest.</p>
    	<p>You have registered for $base day(s) at our Technology Conference</p>
    	<p> You choose  $track as for your track of interest.</p>
    	<p>Please bring cash or your credit card the first day for payment.</p>
    	<p> your Confirmation number is $confId</p>
    	<p> Your total cost including your meal plan option is$$cost</p>
    	<p> We look forward to your participation</p>
       
    	<ul>
    END;
    
    
    
    echo <<<END
    	</ul>
    	
    END;
    	}
    	else						// If errors, display errors
    	{
    		errorMessage($errors);
    	}
    

    Here are you other functions... I think it is what you are looking for, sorry if its not.

    function confID( ){
        return rand(1, 1000);
    }
    function findCost($base, $meal = false){
        
        if(!is_bool($meal))
            $meal = $meal == 'Yes' ? true : false;
        
        $prices = array(
                "One"   => 100,
                "Two"   => 175,
                "Three" => 225
                );
        $meals = array(
                "One"   => 50,
                "Two"   => 75,
                "Three" => 100
                );
        $cost = $meal ? $prices[$base] + $meals[$base] : $prices[$base];
        
        return $cost;
    }
    
    //you can call the confID
    $confID = confID( );
    
    //you can call the find cost function
    //example 1
    $base = 1;
    $meal = 'Yes';
    $cost = findCost($base, $meal);
    //you result would be 150;
    
    //example 2
    $base = 2;
    $cost = findCost($base);
    //your result would be 175
    

  9. <?php

    ///////////////
    //mysql connection here
    //////////////


    $where = 'CategoryID = 1' // if you have any specifications as to which products need to be pulled.
    $order = 'ProductID, ProductName, ProductPrice';
    $result = mysql_query("select * from ProductTable where {$where} order by {$order}");


    echo '<table style="width: 100%; padding: 0px; margin: 0px; border: 0px;" id="Products">';

    while($pline = mysql_fetch_assoc($result)){
    echo '<pre>';
    print_r($pline);
    echo '</pre>';

    //that print_r is just to show you what variables you can print out and what not example
    echo <<<EOT
    <tr>
    <td>Product Name:</td>
    <td>{$pline['ProductName']}</td>
    </tr>
    <tr>
    <td>Price</td>
    <td>{$pline['ProductPrice']}</td>
    </tr>
    EOT;
    }

    echo '</table>';

    mysql_free_result($result);

    ?>

     

  10. <?php 
            
            include 'navigation.php' 
        ?>
        
        <div class='sectionContents'>
        <?php
        if(isset($_GET['action']) && $_GET['action']=='removed'){
            echo "<div>" . $_GET['prod_name'] . " was removed from favourites.</div>";
        }
        
        if(isset($_SESSION['fav'])){
            $ids = array( )
            foreach($_SESSION['fav'] as $prod_id){
                $ids[] = $prod_id; // i see how you were doing it now, sorry mate just woke up 
            }
            
            include "db_connect.php";
     
            $ids = implode(",", $ids);
    
            $query = mysql_query("SELECT prod_id, prod_name, prod_price FROM tbl_product WHERE prod_id IN ('{$ids}')") or die(mysql_error());
                  
            $num = mysql_num_rows($query);
     
            if($num>0){
                echo "<table border='0'>";//start table
                
                    // our table heading
                    echo "<tr>";
                        echo "<th class='textAlignLeft'>Product Name</th>";
                        echo "<th>Price (MUR)</th>";
                        echo "<th>Action</th>";
                    echo "</tr>";
                    
                    //also compute for total price
                    $totalPrice = 0;
                    
                    while ($row = mysql_fetch_assoc($query)){
                        //extract($row);// i dont know where ur extract function it, but im assuming it is taking the key and making that a var, with its correct value
                        foreach($row as $k => $v){
                             $var = $k;
                             ${$var} = $v;
                        }// this should work I havnt tested it
                        
                        $totalPrice += $prod_price;
                        
                        //creating new table row per record
                        echo "<tr>";
                            echo "<td>{$prod_name}</td>";
                            echo "<td class='textAlignRight'>{$prod_price}</td>";
                            echo "<td class='textAlignCenter'>";
                                echo "<a href='remove_favourite.php?prod_id={$prod_id}&prod_name={$prod_name}' class='customButton'>";
                                    echo "<img src='shopping-cart-in-php/images/remove-from-cart.png' title='Remove from favourite' />";
                                echo "</a>";
                            echo "</td>";
                        echo "</tr>";
                    }
                    
                    echo "<tr>";
                        echo "<th class='textAlignCenter'>Total Price</th>";
                        echo "<th class='textAlignRight'>{$totalPrice}</th>";
                        echo "<th></th>";
                    echo "</tr>";
                    
                echo "</table>";
                echo "<br /><div><a href='#' class='customButton'>Home</a></div>";
            }else{
                echo "<div>No products found in your favourites. </div>";
            }
     
        }else{
            echo "<div>No products in favourites yet.</div>";
        }
    ?>
    

    Im not sure it works but i hope so.  When you were adding your favorites you were just over righting the line you currently added.  

  11. I have two results could 

    $result = mysql_query("select CommentID, CommentName, CommentLikes, CommentAuthor, CommentDate from Comments where BlogID = '{$blogID}' and SubComment = '0' and Access >= '{$User->info['Access']}' order by {$sort} limit {$limit}");
    		
    
    $result2 = mysql_query("select CommentID, CommentName, CommentLikes, CommentAuthor, CommentDate from Comments where SubComment = '{$cline['CommentID']}' and Access >= '{$User->info['Access']}'");
    			
    

    can i inner join to get the sub comments right after the main comments, even though they are in the same table?

     

  12. I need help! I have been working on a website for a band and it works all dandy, but I am having a problem. I am trying to make the div where all the content is located scroll down or up if you try to scroll anywhere on the screen. Any help will do, but I have tried using $.scroll and $.scrollTo but still at a lose as to what is going on. I am not a complete noob, I am just unable to figure this one out.

  13. Hey,

     

    My name is Chris, and I would be more than glad to assist you!

    1. First lets create the class in a separate file and include it later.
      <?php
      //this is your class file save it and name it as class.account.php
      class account
      {
      var $ten = array();
      var $clean_inputs = array();
      var $errors = array();
      
      function __construct()
      {
        global $_POST;
        if (isset($_POST['name']) || isset($_POST['email']))
        {
         if ($_POST['name'] == "" || $_POST['email'] == "")
         {
          echo "Please fill out both the name and email!";
          $this->account_form();
         }
         else
         {
          $this->add_account($_POST);
         }
        }
      }
      
      function get_ten(){
        $sql="select * from `account` WHERE ORDER BY id DESC LIMIT 0, 9";
        $result = mysql_query($sql);
        $i = 1;
        while ($row = mysql_fetch_assoc($result)){
         foreach ($row as $z => $x)
         {
          $this->ten[$i][$z] = $x;
         }
         $i++;
        }
      }
      function list_ten()
      {
        $this->get_ten();
        echo "<div style=\"border:solid 1px #F60;\">";
        echo "Last 10 entry:";
        echo "</div>";
        foreach ($this->ten as $z => $x)
        {
         echo "<div style=\"border:solid 1px #000;\">";
         echo "id: {$x['id']}";
         echo "name: {$x['name']}";
         echo "email: {$x['email']}";
         echo "</div>";
        }
      
      }
      function add_account($inputs)
      {
        //first lets clean the inputs
        foreach ($inputs as $z => $x) { $this->clean_inputs[$z] = mysql_real_escape_string($x); }
        $date = date_create(); //get the date
        $timestamp = date_format($date, 'U = Y-m-d H:i:s'); //set the timestamp seeing how I do not know what you guys are doing for this
        $sql = "INSERT INTO account (`name`,`email`,`timestamp`) VALUES ('{$this->clean_inputs['name']}','{$this->clean_inputs['email']}','{$timestamp}')";
        if (mysql_query($sql) or die(mysql_error()))
        {
         $this->account_form();
         $this->list_ten();
        }
        else
        {
         echo "Error creating account, try again!"
         $this->account_form();
        }
      }
      function account_form()
      {
        echo "<div>
        <form action='#' method='POST'>
        name: <input type='text' name='account_name'>
        email:<input type='text' id='account_email'>
        <input type=\"button\" value=\submit\">
        </form>
        </div>";
      }
      
      }
      ?>
      


    2. Include the class file into the main index or .php file
      <?php
      session_start();
      //include ur config script for ur database
      //include class file include("class.account.php");
      include("class.account.php");
      ?>
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
      <html>
      <head>
      <title></title>
      <meta name="" content="">
      </head>
      <body>
      <?php $Account = new account(); ?>
      </body>
      </html>
      


     

    WARNING I HAVE NOT TRIED THIS CODE BUT IT SHOULD WORK IF IT DOES NOT WORK NO WORRIES, IT WAS A QUICK AND EASY 5 MINUTE THING

  14. I am creating a turn based game for my programming class.

    I am creating a hustle function to "hustle" drugs/ deal drugs

    I have a "study" section and the higher you learn about the drug you are hustling the more you will sale.

    My Question is does anyone have an idea of what to do.  If I am not making sense let me know but for now I will show you and example

    say my player has 21 pounds of weed to sale.

    he has 6 hustlers that is part of his crew and he has increased his study to stage 11 which % is 44%

    So I am looking to see what would work best if the user wanted to use 6 turns to sale/hustle 21 pounds of weed.  Any suggestion.  I have part of the script coded but nothing but setting the variables....

  15. got it to work

    <?php
    public function getPlayers() {
    	$Sql = "SELECT * FROM csm_players WHERE uid = '{$this->Uid}'";
    	$Query = mysql_query($Sql);
    	while ($p = mysql_fetch_assoc($Query)) {
    		$Style = stripslashes($this->UserInfo['playerstyle']);
    		$name = explode(" ",$p['name']);
    		$array = array (
    			"{FIRSTNAME}" => $name[0],
    			"{LASTNAME}" => $name[1],
    			"{NICKNAME}" => $p['nickname']
    		);
    		foreach ($array as $key => $val) {
    			$Style = str_replace($key,$val,$Style);
    		}
    		if ($p['cl'] == 1) {
    			if ($this->UserInfo['clba'] == 1) {
    				$Show .= "<font size=\"1\">{$this->UserInfo['clstyle']} {$Style}</font><br>";
    			} else {
    				$Show .= "<font size=\"1\">{$Style} {$this->UserInfo['clstyle']}</font><br>";
    			}
    		} else {
    			$Show .= "<font size=\"1\">{$Style}</font><br>";
    		}
    	}
    	//$Show .= "Error";
    	return $Show;
    }
    

     

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