Jump to content

harristweed

Members
  • Posts

    346
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by harristweed

  1. this works....

    $data["content"]="a load of stuff a load of stuff a load of stuff a load of stuff a load of stuff a load of stuff "; 
      // first find the first space after 40 characters, this should be the end of a word
    $offset =strpos ( $data["content"], " " ,40) ;
    //then put into variable
    $shorter_list = substr ($data["content"],0,$offset);
    //add the trailing dots
    $shorter_list.="....";
    echo $shorter_list;
    

     

    first echo $data["content"] and make sure it has content

  2. To choose the first 40 characters might chop a word in half, I think better to display whole word.

    // first find the first space after 40 characters, this should be the end of a word
    $offset =strpos ( $data["content"], " " ,40) ;
    //then put into variable
    $shorter_list = substr ($data["content"],0,$offset);
    //add the trailing dots
    $shorter_list.="....";
    

  3. As jl5501 pointed out, you are not actually reading the file....try

    mysql_connect ("localhost","username","password"); 
    mysql_select_db ("database_name"); 
    // Path to the data file 
    $path="test.txt"; 
    
    // Get the site of the file 
    $filesize=filesize($path); 
    // Open file, read its data and close it 
    $filenum=fopen($path,"r"); 
    
    $contents = fread($filenum, filesize($filesize));
    fclose($filenum); 
    
    $bits=explode(",",$contents);
    $arrlen = count($bits);
    
    // Listing the array inside a loop, adding it to the database and echo about it. 
    for($i=0; $i<$arrlen ; $i++){
    
    $sql_insert = mysql_query("REPLACE INTO case_numbers (casenumber,casename) VALUES ('$bits[0]','$bits[1]'");
    
    $result = mysql_query ($sql_insert); 
    // reports an error if insert fails. 
    if (!$result)echo mysql_error(); 
    }
    // All done, let's go home! 
    echo "All rows imported successfully!"; 

  4. It's not a PHP problem it's an HTML problem:

     

    $select = "selelected = \"selected\" ";
    
    print '<td width="160"><p align="right">State</td>';
    print '<td width="600"><p align="left"><select name="state">';
    print '<option value="0" ';
    if(empty($state)echo $select;
    print '>Select Your State</option>';
    print '<option value="AL" ';
    if($state=="AL")echo $selec;
    print'>Alabama</option>';
    print '<option value="AS" ;
    $state=="AL")echo $selec;
    >American Samoa</option>';
    print '<option value="AK" ';
    
    $state=="AK")echo $selec;
    print'>Alaska</option>';

     

    etc.....

     

     

     

  5. it's a while since I set my laptop up (vista=nightmare) but I do remember:

    in httpd.conf

     

    line 117 reads: LoadModule php5_module "c:/php/php5apache2_2.dll"

     

    line 119 reads:AddType application/x-httpd-php .php

     

    and you must also:

    # configure the path to php.ini

    PHPIniDir "C:/php"

     

    line 406 is:

        ScriptAlias /php/ "C:/php/"

        AddType application/x-httpd-php .php .php5

        Action application/x-httpd-php "/php/php-cgi.exe"

        SetEnv PHPRC "C:/php"

     

    check those

     

  6. I'd do it like this, make the cd list the link and have the relevant cd in query string:

     

    <?php

        $Row = mysqli_fetch_row($QueryResult);

    do {

      echo "<table width='100%' border='1'>";

      echo "<tr><th>CD Type</th><th>CD Name</th><th>Price</th><th>Artist</th></tr>";

      echo "<tr><td>{$Row[0]}</td>";

      echo "<td><a href=\"update.php?cd=$Row[1]\">{$Row[1]}</a></td>";

      echo "<td>{$Row[2]}</td>";

      echo "<td>{$Row[3]}</td></tr>";

     

      echo '<a href="index.html"> Delete</a>';

      $Row = mysqli_fetch_row($QueryResult); 

    } while($Row);

    ?>

  7. The tm symbol is & # 8 4 8 2 (without the spaces) perhaps you could do a replace:

     

      $gameid=str_replace("search","™",$gameid); // search is what ever you have in the databse for tm

  8. while($row = mysql_fetch_object($result))

                  {     

                      echo "<tr align='center'><td>";

                      echo $row->KEGG_ID;

                      echo "</td><td>";

                      echo $row->Gene_Name;

                      echo "</td><td>";

                      echo $row->Uniprot_ID;

                      echo "</td><td>";

                     

                  }

     

     

    Try:

    while($row = mysql_fetch_object($result))

                  {     

                      echo "<tr align='center'><td>";

                      echo $row->KEGG_ID;

                      echo "</td><td>";

                      echo $row->Gene_Name;

                      echo "</td><td>";

                      echo $row->Uniprot_ID;

                      echo "</td></tr>";

                     

                  }

  9. I think that you are mistaken about which are the 'bad' characters.

     

    This is a line 338 taken from the validator"<description>please visit site<![CDATA[Very clean 2005 Honda Civic DX(Value Package), Low miles â\x80\x93 31,300, Auto Trans, Blue,"

     

    '\x80' is the euro symbol

    I'm not sure what \x93 is but you can tell from the original code so you need to do a string replace i.e.

     

    $bad=array("\x80","\x93");
    $good=array("&#8364;","?????");
    $xml=str_replace($bad,$good,$xml);

     

    Also "please visit site" needs to be inside the cdata tags.

  10. Sorry, It was a bit late last nigt. Try:

     

    <?php
    
    
    function find_day($transit_time){    
        
      
    $today = time ();
    $year = date("Y", $today);
    $month = date("m", $today);
    $day = date("j", $today);
    $today_day = date("l", $today);
    $hour= date("H", $today);
    $weekday = date("w");
    
      
      if(($weekday==1 && $transit_time < 5)|| ($weekday==2 && $transit_time < 4)||($weekday==3 && $transit_time < 3)||($weekday==4 && $transit_time < 2)){
      
    $delivery_date=mktime($hour, $minute, $second, $month, $day+$transit_time, $year);     
          
      }else{
       //add 2days for every weekend     
        $weekends=floor($transit_time/7)*2; //already one weekend because we got to this bit! This calculates additional weekends
        $total_days=$transit_time+$weekends+2;// need to add one that weekend!
        $delivery_date=mktime($hour, $minute, $second, $month, $day+$total_days, $year);
      }
    return $delivery_date;
    }//end function find_day
    
    $transit_time = "3";
    
    $delivery_date = find_day($transit_time);
    echo date("l F j, Y", $delivery_date);
    ?> 

  11. I think Corbins answer is very good however if you don't have php 5.1

     

    I'd do this....

    /*  
      0=Sunday
      1=Monday
      2=Tuesday
      3=Wednesday
      4=Thursday
      5=Friday
      6=Saturday
      */
      
      $today=date("w");
      
      
      if(($today==1 && $number_of_days < 5)|| ($today==2 && $number_of_days < 4)||($today==3 && $number_of_days < 3)||($today==4 && $number_of_days < 2)){
      
    $delivery_date=mktime($hour, $minute, $second, $month, $day+$number_of_days, $year);     
          
      }else{
       //add 2days for every weekend     
        $weekends=floor($number_of_days/7)*2;
        $total_days=$number_of_days+$weekends;
        $delivery_date=mktime($hour, $minute, $second, $month, $day+$total_days, $year);
      }

  12. I use a different method that seems to work. To stop botts sending forms, I have (for example) an email form field called antibott. So the variable $antibott hold the users email. I also have a form text field called 'email'. This is in a separate div Using CSS I make this div invisible so humans can't see it!. Therefore if the variable $email is NOT empty the form was filled in by a bott and the form redirects to a page that only botts see!

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