Jump to content

kratsg

Members
  • Posts

    898
  • Joined

  • Last visited

    Never

Posts posted by kratsg

  1. Hey,

     

    I'm having an issue with using Wikipedia's OpenSearch API - it sometimes gives me characters in a unicode format: "\u00f1" and I would like to convert back into a correctly displayed format (in this case, n-tilde; spanish n).

     

    Any suggestions?

  2. I like to point out the function of "foreach" from php.net/foreach

     

    "Unless the array is referenced, foreach operates on a copy of the specified array and not the array itself. foreach has some side effects on the array pointer. Don't rely on the array pointer during or after the foreach without resetting it. "

     

    IE: you'll want to pass by reference if you wish to change the original array.

     

    Edit: It might help to notice that your echo statement is WITHIN a foreach loop (so it references the copy of the array). You should be able to fix this by changing the one line:

     

    foreach ($siteList as $sitePrefix => &$siteAttributes) {
    

     

    This should pass the reference of siteAttributes without making a copy.

  3. Let me better phrase this question...

     

    Let's say I focus on some of the more commonly used functions in mysql:

     

    mysql_connect, mysql_select_db, mysql_query, mysql_fetch_result/array, mysql_real_escape_string, mysql_free_result...

     

    It appears that almost all of these exist, except for the "pg"_real_escape_string. Is there a replacement for this or a way to prevent SQL Injection similarly with postgres?

  4. Hey Guys,

     

    I'm having a problem with a really basic script... it's so basic that I can't imagine what's going wrong at all:

     

    $filename = "ip.address";
    chdir('../');
    $file = fopen($filename,"a+");
    

     

    The directory looks something like this:

     

    -svn/

    -public/

    --ip.address

    --html/

    ---MYPHPSCRIPT.php

     

    I use the chdir('../') to go up one directory (into public/ directory). Inside that is a file called ip.address. Now, I can't even open that file (I can obviously read it as file_get_contents works but I can't write to it).

     

    Going with file permissions - I set it to 0777 for the file and it still doesn't work. I'm at a loss.

     

    Edit: To clarify, it gives me a "Permission denied in (this php script file) error.

    Edit 2: allow_url_fopen is set to on for both Global and Local

  5. Hey,

     

    I don't particularly have a problem. It was just interesting when I dumped the object to see exactly what happened with the stored values (since I did use a join) and I was wondering if the periods also carried over in the property names:

     

    	$statement_paginate = "SELECT perms.pid, perms.description, user_perms.expires FROM perms, user_perms WHERE user_perms.fk_uid = '$user_id' AND perms.pid = user_perms.fk_pid ORDER BY perms.pid ASC";
    

     

    They appear not to. No problem here.

     

    Thanks!

  6. Just a quick question for anyone who knows:

     

    Does mysql_fetch_*****() always return values from the database in the form of strings (regardless of what data type it is set in the database?)

     

    The reason I ask is I did something like the following:

     

    while($row = mysql_fetch_object($curr_data)){
    var_dump($row);
    //....
    //....
    }
    

     

    Which outputted

     

    object(stdClass)#1 (3) { ["pid"]=>  string(1) "1" ["description"]=>  string(35) "Allows user to view survey results." ["expires"]=>  string(1) "0" }
    

     

    Now, 'pid' and 'expires' are both set as integers in the database. There's nothing wrong with the values, but rather the type of values they are.

     

    ~kratsg.

  7. My initial guess is this portion:

     

    preg_match_all("/(?:[^\\]|^)(?:\[link:([a-zA-Z0-9=,]*)\])/",stripslashes($_GET['d']),$matches);

     

    I believe you need 3 or 4 backslashes (I saw this before) to get a literal backslash. Let me find that post. Edit: Here it is

     

    http://www.phpfreaks.com/forums/index.php/topic,301552.msg1427102.html#msg1427102

     

    It's not a bug, you firstly need to account for what PHP thinks is an backslash escape sequence, you then need to account for what PCRE considers an escape sequence. You are using a double quote inside a double quoted string, thus meaning it needs to be escaped, there's one backslash. You then wish to match a backslash in your input string. In order to do this let's say we place a single quote in the string. PHP will see this as escaping the backslash which is supposed to be escaping the double quote, thus you need to escape it to prevent that happening. At this point we have 3 backslashes in our patterns. Out of these 3 only one will survive the PHP interpolation. Meaning the Regex pattern contains a single slash. The PCRE engine will assume this backslash is an escape sequence. In order to counter that we need to make sure 2 make it through the the PCRE engine, the only way to do this is add another 2 into the string. That's 5 backslashes.

  8. Well, while this "isn't" the board for it... here's a shot...

     

    You can create two checkbox groups and show one or the other:

     

    <script type='text/javascript'>
    function getCheckboxes(target){
    var x = document.getElementsByClassName("checkboxes");
    for(i=0;i<x.length;i++){
    	if(x[i].getAttribute('rel') == target){
    		x[i].style.display = 'inline';
    	} else {
    		x[i].style.display = 'none';
    	}
    }
    }
    </script>
    
    <a href="#" onclick="getCheckboxes('patent');return false;">Patents</a> | <a href="#" onclick="getCheckboxes('manufacturer');return false;">Manufacturer</a>
    
    <form name="some_form">
    <input type="checkbox" class="checkboxes" rel="patent" value="1" />
    <input type="checkbox" class="checkboxes" rel="patent" value="2" />
    <input type="checkbox" class="checkboxes" rel="patent" value="3" />
    <input type="checkbox" class="checkboxes" rel="patent" value="4" />
    <input type="checkbox" class="checkboxes" rel="patent" value="5" />
    
    <input type="checkbox" class="checkboxes" rel="manufacturer" value="1" />
    <input type="checkbox" class="checkboxes" rel="manufacturer" value="2" />
    <input type="checkbox" class="checkboxes" rel="manufacturer" value="3" />
    <input type="checkbox" class="checkboxes" rel="manufacturer" value="4" />
    <input type="checkbox" class="checkboxes" rel="manufacturer" value="5" />
    </form>
    
    <script type='text/javascript'>
    getCheckboxes("patent");
    </script>
    

     

    Edit: Two typos, the above code works perfectly now.

  9. Actually, you don't need to check if it's set if you're only looking for ONE specific value of it...

     

    <form action="calculator.php" method="post">
      <p>Quantity:
           <select name="quantity">
    <option value= "100" <?php echo ($_POST['quantity'] == 100)?'selected="selected"':''; ?>>100</option>
                    <option value= "250" <?php echo ($_POST['quantity'] == 250)?'selected="selected"':''; ?>>250</option>
                    <option value= "500" <?php echo ($_POST['quantity'] == 500)?'selected="selected"':''; ?>>500</option>
      </select> </p>
            <p>Double sided
              <INPUT TYPE="radio" NAME="q1" VALUE="yes">
               Single Sided
               <INPUT TYPE="radio" NAME="q1" VALUE="no">
    
            <p>Total: £<?php echo $sum?></p>
        <p><input type="submit" name="submit" value="Calculate!" /></p>
      <input type="hidden" name="submitted" value="TRUE" />
    </form>

     

    Or better yet, if there's a lot of values:

     

    <form action="calculator.php" method="post">
      <p>Quantity:
           <select name="quantity">
    <?php
    $possible_vals = array(100,250,500);
    foreach($possible_vals as $value){
         echo "<option value= '$value'";
         if($value == $_POST['quantity']){
              echo ' selected=\'selected\'';
         }
         echo ">$value</option>";
    }
    ?>
      </select> </p>
            <p>Double sided
              <INPUT TYPE="radio" NAME="q1" VALUE="yes">
               Single Sided
               <INPUT TYPE="radio" NAME="q1" VALUE="no">
    
            <p>Total: £<?php echo $sum?></p>
        <p><input type="submit" name="submit" value="Calculate!" /></p>
      <input type="hidden" name="submitted" value="TRUE" />
    </form>

  10. There are two ways:

     

    1.) Just retrieve your own status regardless and just add that to the list.

    2.) Re-write the query to be something like...

     

    $friend_statuses = "SELECT status.*, friends2.user1 FROM status, friends2 WHERE status.byuser IN (friends2.user1,'myself') AND friends2.user2='$username' ORDER BY status.dtime DESC";
    

  11. PHP.net:

     

    ob_start  — Turn on output buffering

    Report a bug

    Description

    bool ob_start ([ callback $output_callback [, int $chunk_size [, bool $erase ]]] )

     

    This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.

  12. He's going to need quotes for states like "New York" that have a space in them. Here's the appropriate query:

     

    <?php
    $query = "SELECT * FROM `table_suburbs` WHERE `state`='$state' ";
    
    if(mysql_num_rows($query)==0){
         die('No results returned!');
    }
    
    echo "<table><tr><td>Suburb</td><td># Nurses</td><td>Suburb</td><td># Nurses</td></tr>";
    $i = 0;//indexing variable
    
    while($row = mysql_fetch_array($query)){
         if($i%2){echo "</tr>";}else{echo "<tr>";}
         echo "<td>{$row['suburb']}</td><td>{$row['nurses']}</td>";
         $i++;
    }
    
    if($i%2){echo "<td> </td><td> </td>";}
    echo "</tr></table>";
    ?>
    

     

    I have an indexing variable which keeps track of which column you are in (left column = even; $i%2=0.... right column = odd; $i%2=1). See if it makes sense?

    No qutoes!

    select * from table_suburbs where state=ohio

     

    You can do this by putting foreach in foreach. Please explain it so it would be understandable, I don't get what do you want.

     

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