Jump to content

NotionCommotion

Members
  • Posts

    2,446
  • Joined

  • Last visited

  • Days Won

    10

Community Answers

  1. NotionCommotion's post in Curl Request Append Response was marked as the answer   
    Okay, $textAr includes URLs for www.google.com\r and www.yahoo.com.  Do you really want the \r with Google?
    Then I see $line: www.google.com being echoed, but don't see the results being echoed.  Replace print_r with var_dump as it likely is returning NULL.
    Then I see $line: www.yahoo.com followed by the error message.  I would have expected a line break but not a big deal.
    Then I see the $results array with the first element being empty and the second being the error response.
    Isn't this what you were expecting?  Consider changing $result[] = $r; to $result[$line] = $r; to make it more clear.
  2. NotionCommotion's post in How to restrict mySQL results to single instance after using mb_substr was marked as the answer   
    Instead of having PHP do the trimming, have MySQL do it.  See http://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_left.
     
    Do, why won't DISTINCT or GROUP BY work?.  Are there records like ABCfoo and ABCbar? Maybe the following?
    SELECT DISTINCT LEFT(order_discount_code,3) FROM orders ORDER BY order_discount_code ASC;
  3. NotionCommotion's post in How to Display Individual Tables in Dropdowns from SQL? was marked as the answer   
    Not sure I understand your question, so forgive me if you already know this.
     
    Every time the browser makes a request to the server, it should include the region name in the URL (maybe use a default region name if none provided, and be sure to use isset() or something to make sure it exists). You then get the data based on the region name, pass it to a template, and display it.
    $stmt = $conn->prepare('SELECT x,y,z FROM yourTable WHERE Region_Name=:Region_Name'); $stmt->execute(['Region_Name'=>$_GET['Region_Name']]); $rs=$stmt->fetch(); yourTemplate($rs);
  4. NotionCommotion's post in How do I extract partial string from a full string? was marked as the answer   
    Maybe?
    <?php function getIt($var) {     $pos = strpos($var, ' - ');     echo(substr($var, $pos+3)."\n"); } $variable_1 = 'Lulu-free - Swimsuit swimwear red'; $variable_2 = 'Pap & Jones - Bard Mini Dress'; getIt($variable_1); getIt($variable_2);
  5. NotionCommotion's post in Preventing Twig from escaping JSON was marked as the answer   
    Ah, I see.
    {% set _jsScript = [ 'var types='~types|json_encode()~';' ] %} {% macro listArray(list) %} {% for item in list %} {{ item|raw }} {% endfor %} {% endmacro %} {% if _jsScript|default %} <script type="text/javascript">     {{ forms.listArray(_jsScript) }} </script> {% endif %}
  6. NotionCommotion's post in PHP string adding extra forward slash was marked as the answer   
    Yea, that was the reason I added "EDIT.  Please disregard (and hopefully delete this post), I am just blind." to the original post.
  7. NotionCommotion's post in security related was marked as the answer   
    It is good that you are aware of real_escape_string(), however, no one uses it anymore.  Instead, use a prepared statement ideally PDO.  While there is fancy binding and the like, start off simple.
    $username = $_SESSION[info]['username'];         $query = "SELECT $column FROM $table WHERE username =? limit 1"; //Why not hard code your column and table names? $stmt->$yourDataBaseConnection->prepare($query); $stmt->execute([$username]); $rs=$stmt->fetch(); //Or fetchAll() or fetchColumn().  Also, add parameters such as PDO::FETCH_OBJ.
  8. NotionCommotion's post in Array Inside Multidimensional Array was marked as the answer   
    Try the following.  Also, experiment with using $key=>$value in your foreach loops.
    <?php $array=[     'catalog'=>[         [             'attributes'=>['book'=>20160122],             'section'=>[                 ['id'=>'F100','title'=>'Across the Sea'],                 ['id'=>'F101','title'=>'Blue Water'],                 ['id'=>'F102','title'=>'Red Rove']             ]         ],         [             'attributes'=>['book'=>20160123],             'section'=>[                 ['id'=>'F103','title'=>'xAcross the Sea'],                 ['id'=>'F104','title'=>'xBlue Water'],                 ['id'=>'F105','title'=>'xRed Rove']             ]         ], ]]; foreach($array['catalog'] as $catalog){     echo('Book: '.$catalog['attributes']['book']."\n");     foreach($catalog['section'] as $section){         echo($section['id'].' '.$section['title']."\n");     }     echo("\n"); } ?>
  9. NotionCommotion's post in Character issues when using DOMDocument was marked as the answer   
    Solved by using $message = mb_convert_encoding($message, 'HTML-ENTITIES', 'UTF-8');
     
    Note that $message= str_replace(' ', ' ', $message); is also no longer needed.
  10. NotionCommotion's post in How would you check if a variable was submitted into a field then submit it to the PDO statement? was marked as the answer   
    Maybe something like the following...
    <?php $data=array(); $query=''; foreach(array('name','phone') as $key) {     if(isset($_POST[$key]) && $_POST[$key]!=''){         $data[$key]=$_POST[$key];         $query.="$key=:$key,";     } } if(!empty($data)){     $sql = 'UPDATE myTable SET '.trim($query, ",").' WHERE id=:id';     $data['id']=123;     $q = $conn->prepare($sql);     $q->execute($data); }
×
×
  • 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.