Jump to content

OldWest

Members
  • Posts

    296
  • Joined

  • Last visited

    Never

Posts posted by OldWest

  1. PFMaBiSmAd,

     

    I'm sorry for wasting your time. You're right. I've been on the pc for 10 hours straight like mud mind right now.. But that's for the refresher. It's working now. All I needed to do was remove the foreach().

     

    $queryCats = "SELECT id, cateName FROM ads_cate";
    $resultCats = mysql_query($queryCats); 
    while ($category = mysql_fetch_array($resultCats, MYSQL_ASSOC)) {
            echo '<a href="'."/search_list.php?type=items&keyword=&cate=".$category['id'].'">' . $category['cateName'] . '</a><br />';

     

  2. My code IS working, but there is a problem. I am only trying to echo the link and category name, but I am getting two urls which I cannot resolve. Some hours into this now and frustrated, so any tips are welcome:

     

    For some reason the id is also echoing a full url why?

     

    Current code:

     

    <?php
    $queryCats = "select id, cateName from ads_cate";
    $resultCats = mysql_query($queryCats); 
    while ($category = mysql_fetch_array($resultCats, MYSQL_ASSOC)) {
        foreach ($category as $cat_name) {
            echo '<a href=' . "search_list.php?type=items&keyword=&cate=" . $category['id'] . ">" . $cat_name . '</a><br />';
        }
    }
    ?>

     

    Current Output?????

     

    <a href=search_list.php?type=items&keyword=&cate=1>1</a>

    <a href=search_list.php?type=items&keyword=&cate=1>Appliances</a>

    <a href=search_list.php?type=items&keyword=&cate=2>2</a>

    <a href=search_list.php?type=items&keyword=&cate=2>Automobiles / Trucks</a>

    ....

     

    WHy is the id also echoing? I am not printing it to the url???

     

     

  3. You're welcome ; )

     

    <html>
    <head>
    </head> 
    </body> 
    <form method="post" action="<?php
      echo $_SERVER["PHP_SELF"];
    ?>"> 
    <table> 
    <tr><td>Name:<input type="text" name="name" size="10"></td></tr> 
    <tr><td>Say what you want: <input type="text" name="you_typed" size="50"></td></tr> 
    <tr><td><input type="submit" name="submit" value="Give me the data!"></td></tr> 
    </table>
    </form> 
    </body> 
    </html>
    
    <?php
      
      class echoIt
      {
          
          var $name;
          var $you_typed;
          function passed($arg1, $arg2)
          {
              $this->name = $arg1;
              $this->you_typed = $arg2;
          }
      }
      $your_name = $_POST['name'];
      $what_you_typed = $_POST['you_typed'];
      $output = new echoIt();
      $output->passed($your_name, $what_you_typed);
      echo "Your name is " . $output->name . " and you typed: " . $output->you_typed . ".";
    ?>

     

  4. if i understand what you are trying to do correct, php has several function shat can get the ip address like

    $_SERVER['REMOTE_ADDR'];

    .. and you can just bypass the login credentials and start your session for the user with their ip address as the credentials... hope this helps

  5. My bad!! Ignore my earlier post.. is this what you are trying to do? RUN my code to see the output..

    <?php
      $string=' de s pres div de d an Agt ';
    
    //DEFINE PATTERN
    $patterns = array();
    $patterns[0] = '/ s /';
    $patterns[1] = '/ b /';
    $patterns[2] = '/ pres /';
    $patterns[3] = '/ Ind /';
    $patterns[4] = '/ Mar /';
    $patterns[5] = '/ Agt /';  
    $patterns[6] = '/ Agy /';  
    $patterns[7] = '/ Indpls /';                            
    $patterns[8] = '/ Chgo /';
    $patterns[9] = '/ Corp /';
    $patterns[10] = '/ U /';    
    $patterns[11] = '/ Fin /';          
    $patterns[12] = '/ ls /';   
    $patterns[13] = '/ Pres /';    
    $patterns[14] = '/ Internat /';   
    $patterns[15] = '/ m /';
    $patterns[16] = '/ N Y C /';   
    $patterns[17] = '/ div /';   
    $patterns[18] = '/ de /';  
    $patterns[19] = '/ d /';    
    
      
    
    
    //DEFINE PATTERN REPLACE
    $replacements = array();
    $replacements[0] = ' son of ';
    $replacements[1] = ' born in ';
    $replacements[2] = ' president ';
    $replacements[3] = ' Indiana ';
    $replacements[4] = ' March ';
    $replacements[5] = ' Agent ';  
    $replacements[6] = ' Agency ';  
    $replacements[7] = ' Indianapolis ';                            
    $replacements[8] = ' Chicago ';
    $replacements[9] = ' Corporation ';
    $replacements[10] = ' U '; 
    $replacements[11] = ' Financial ';       
    $replacements[12] = ' Island ';   
    $replacements[13] = ' President '; 
    $replacements[14] = ' International ';  
    $replacements[15] = ' married to ';
    $replacements[16] = ' New York City ';   
    $replacements[17] = ' divorced ';    
    $replacements[18] = ' de '; 
    $replacements[19] = ' daughter of ';    
    
    echo '------ Original ---------<br>'.$string.'<br>';
    $data = preg_replace($patterns, $replacements, $string);
    echo '<br>------ Abbreviation Replace ---------<br>'.$data.'<br>';  
    ?>

     

  6. . has a special meaning in regular expressions. If you want a literal period then you have to escape it with a backslash.

     

    Try with that change.

     

    Yeah you're right. This works:

    <?php
      $string='de d s pres div de de d s';
    
    //DEFINE PATTERN
    $patterns = array();
    $patterns[0] = '/ s\. /';
    $patterns[1] = '/ b\. /';
    $patterns[2] = '/ pres\./';
    $patterns[3] = '/ Ind\./';
    $patterns[4] = '/ Mar\./';
    $patterns[5] = '/ Agt\./';  
    $patterns[6] = '/ Agy\./';  
    $patterns[7] = '/ Indpls\./';                            
    $patterns[8] = '/ Chgo\./';
    $patterns[9] = '/ Corp\./';
    $patterns[10] = '/ U\./';    
    $patterns[11] = '/ Fin\./';          
    $patterns[12] = '/ ls\./';   
    $patterns[13] = '/ Pres\. /';    
    $patterns[14] = '/ Internat\. /';   
    $patterns[15] = '/ m\. /';
    $patterns[16] = '/ N\.Y\.C\./';   
    $patterns[17] = '/ div\. /';   
    $patterns[18] = '/ de /';  
    $patterns[19] = '/ d\. /';    
    
      
    
    
    //DEFINE PATTERN REPLACE
    $replacements = array();
    $replacements[0] = ' son of ';
    $replacements[1] = ' born in ';
    $replacements[2] = ' president';
    $replacements[3] = ' Indiana ';
    $replacements[4] = ' March ';
    $replacements[5] = ' Agent ';  
    $replacements[6] = ' Agency ';  
    $replacements[7] = ' Indianapolis ';                            
    $replacements[8] = ' Chicago';
    $replacements[9] = ' Corporation ';
    $replacements[10] = ' U '; 
    $replacements[11] = ' Financial ';       
    $replacements[12] = ' Island';   
    $replacements[13] = ' President '; 
    $replacements[14] = ' International ';  
    $replacements[15] = ' married to ';
    $replacements[16] = ' New York City ';   
    $replacements[17] = ' divorced';    
    $replacements[18] = ' de '; 
    $replacements[19] = ' daughter of ';    
    
    echo '------ Original ---------<br>'.$string.'<br>';
    $data = preg_replace($patterns, $replacements, $string);
    echo '<br>------ Abbreviation Replace ---------<br>'.$data.'<br>';  
    ?>

     

  7. I am doing some study on using time() and date() and i just wrote this simple for loop to add one day to each iteration with +$i and its echoing the unix timestamp as opposed to the correctly formated date as it should be based on my code. Anyone have any idea why this is not working as expected?

     

    for($i=0; $i < 50; $i++)
    {
    echo $time = time()+$i . "<br />"; // add a day on each iteration
    echo date('y-m-d', $time) . "<br />"; // should echo 10-12-02, 10-12-03, 10-12-04, etc..
    }

     

    what am i doing wrong here? arrgggg! maybe its too late for this s$%^#!

     

  8. I am just curious on some recommendations for the best format to store time in a table for later date comparison.

     

    I was thinking time() is probably the best method as it store in epoch seconds I believe, and that can be formatted with date() easily, but I also heard this is not always accurate.

     

    Please tell me any recommendations on this!

    And suggestions or ideas on this?

  9.  

    Ok I was able to get it to work, but I am not sure why the output is showing in negatives. I did this and it seems to work as expected now. Is there a smarter or better way to do this to ensure the time count is exact and accurate?

     

    $ad_start = time()-14 . "<br />"; 
    echo $ad_start;
    
    $current_time = time() . "<br />";
    echo $current_time;
    
    $days_past = $ad_start - $current_time;
    
    echo "<br />$days_past days have past since the ad started!<br />";
    
    if($days_past >= -14)
    {
    	echo "<br />Ad is less than 14 days.  Not expired.";
    }
    else
    {
    	echo "<br />Ad is over 14 days. Expired.";
    }

  10. I am trying to simulate an ad expiration and carry out an action if the ad is expired. And I cannot get the if/else to work properly... I've tried many variations and I cannot see what I am doing wrong here. Any tips please 3 hours and counting of no solution!

     

    $ad_start = time()-14 . "<br />"; // 14 days from today in the past (negative)
    echo $ad_start;
    
    $current_time = time() . "<br />"; // current epoch time
    echo $current_time;
    
    $days_past = $ad_start - $current_time; // days past
    
    echo "<br />$days_past days have past since the ad started!<br />";
    
    if($days_past <= 14)
    {
    	echo "<br />Ad is less than 14 days.  Not expired.";
    }
    else
    {
    	echo "<br />Ad is over 14 days. Expired.";
    }

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