Jump to content

kenrbnsn

Staff Alumni
  • Posts

    8,234
  • Joined

  • Last visited

Posts posted by kenrbnsn

  1. If the URL is always going to look similar to that example, you can do something like

    <?php
    $str = 'http://www.amazon.co.uk/gp/aw/d/B004JN01LW/ref=mp_s_a_1?qid=1305169492&sr=8-1';
    $x  = parse_url($str);
    list(,,,,$part) = explode('/',$x['path']);
    echo $part . "<br>";
    ?>

     

    Ken

     

  2. Either

    <?php
    $query1 = "SELECT distinct link_id, url, title, description, " . stripslashes($fulltxt) . ", size FROM ".$mysql_table_prefix."links WHERE link_id in ($inlist)";
    
    	$result = mysql_query($query1);
    	echo mysql_error();
    ?>

    or

    <?php
    $fulltxt = stripslashes($fulltxt);
    $query1 = "SELECT distinct link_id, url, title, description, $fulltxt, size FROM ".$mysql_table_prefix."links WHERE link_id in ($inlist)";
    
    	$result = mysql_query($query1);
    	echo mysql_error();
    ?>

     

    Ken

  3. Do

    <?php
    echo "<a href='viewprofile.php?username={$info['username']}'><img src='http://datenight.netne.net/images/{$info['img']}'  title='{$info['username']}' width='50' height='50'></a>";
    ?>

     

    No escaped double quotes. Much cleaner IMHO.

     

    Ken

  4. If you use the explode method, you can use the little used third parameter to explode to limit the number of parts returned:

    <?php
    $strs = array('1. item number 1',
    '12. item number 12',
    '101. item number 101');
    foreach ($strs as $str) {
       list (,$str) = explode('.',$str,2);
       echo ltrim($str) . "<br>\n";
    }
    ?>

     

    Ken

  5. The $_REQUEST array is populated via information on the URL or from a form. You really should use the $_GET array if the values are coming from the URL (or a form using the "get" method) or the $_POST array if the values come from a form with using the "post" method.

     

    At the top of your script, put:

    <?php
    if (isset($_POST)) {
      echo '<pre>$_POST: ' . print_r($_POST, true) . '</pre>';
      echo '<pre>$_GET: ' . print_r($_GET,true) . '</pre>';
    ?>

    This will dump to the screen these arrays in a readable way.

     

    To get around your problem, do something like:

    <?php
    if(isset($_REQUEST['username']) && $_REQUEST['username'] == "rotten" && isset($_REQUEST['password']) && $_REQUEST['password'] == "1212"){
    $_SESSION['username'] = "rotten";
    $_SESSION['password'] = "1212";
    header("Location: home.php ".$_SESSION['pageredirect']);
    }
    ?>

    The isset function checks to see if the array entry is there before checking the value.

     

    Ken

  6. You can also write it like

    <?php
    $image = "<img src='images/flags/{$row_rsPilots['country']}.gif' alt='' name='Flag' width='20' height='20' />";
    $link = "http://www.domain.com/{$row_rsPilots['country']}";
    if (!empty($rsPilots['country'])) {
    echo "<a href='$link'>$image</a>";
    }
    ?>

    which gets rid of the escaped double quotes and looks cleaner (IMHO).

     

    Ken

  7. Instead of doing this

    <?php
    $concertDates = array();
    ?>

    at the start of your script, initialize the array with the values and remove all other lines that populate the array:

    <?php
    $concertDates = array('201105071'=>'May 7, 2011 (9:00am - 12:00pm)',
        '201105072'=>'May 7, 2011 (1:00pm - 4:00pm)',
        '201105141'=>'May 14, 2011 (9:00am - 12:00pm)');
    ?>

     

    Ken

  8. You're returning the totalcount from the function, but not doing anything with it when you call the function recursively. Try something like:

    <?php
      include 'config.php';  // Connect database
    
      function leftcount($node)   //Function to calculate leftcount
      {
        $sql = "SELECT lchild,rchild FROM tree WHERE parent = '$node'";
        $execsql = mysql_query($sql);
        $array = mysql_fetch_array($execsql);
        
        if(!empty($array['lchild']))
        {
          $count += leftcount($array['lchild']);  
        } 
        if(!empty($array['rchild']))
        {
           $count += leftcount($array['rchild']); 
        }
        
        $totalcount = 1 + $count;
        return $totalcount;
        
      }
      
      $parent = "2";
      $left = leftcount($parent);
      echo $left;
      
    ?>

     

    Ken

     

  9. Using a slash at the start of a path like that, say to start at the root of the whole file system, which is not what you want.

     

    You want to do something like

    <?php
    require_once $_SERVER['DOCUMENT_ROOT'] . '/config.inc.php';
    ?>

     

    If your file is in the webroot.

     

    Ken

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