Jump to content

benanamen

Members
  • Posts

    2,134
  • Joined

  • Last visited

  • Days Won

    42

Community Answers

  1. benanamen's post in syntax Help passing a Variable was marked as the answer   
    Most likely {$row['id']}
     
    Whatever your ID column is named.
    echo "<tr><td><a href=\"kf_orders_entered_detail.php?id={$row['id']}\">{$row['ompCreatedBy']}</td>";
  2. benanamen's post in Separating two variables in an image string was marked as the answer   
    echo "<td width=\"100\"><div align=\"center\"><img src=\"http://www.brickbybricks.ca/php/images/{$row['Color_Name']}/{$row['PartID']}.gif\"></td>";  The only thing about that is you have no choice but to escape and concatenate the variables instead of doing {$row['Color_Name']} (Curly Syntax, my preference). 
  3. benanamen's post in Need help with SELECT WHERE statement was marked as the answer   
    Ok, we are getting somewhere.
     
    Now, just use this code alone while you get things going. The difference is I have now added what is called a "Positional Placeholder" for username which is the question mark. There is another way to do it called "Named Parameters" but we can get into that another time. The code will now give you the individual column data.
     
    This is complete standalone with the connection code. Just practice with this. you can integrate it later. Set the connection parameters to your DB.
     
     
    <?php
    error_reporting(-1);
    ini_set('display_errors', '1');

    $hostdb   = 'localhost';
    $dbname   = 'phphelp_joe';
    $username = 'root';
    $password = '';

    if (!empty($_GET['username']))
        {  
        $pdo = new PDO("mysql:host=localhost;dbname=$dbname", $username, $password);
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        
        $sql  = "SELECT username, firstname, lastname, email FROM users WHERE username=?";
        $stmt = $pdo->prepare($sql);
        $stmt->execute(array(
            $_GET['username']
        ));
        $row = $stmt->fetch();
        echo "{$row['username']} {$row['lastname']} {$row['email']}";
        }
    else
        {
        echo 'No username in URL';
        }
    ?>
  4. benanamen's post in Sql without 000-00-00 date was marked as the answer   
    Add this to your query
    AND t1.`data_prevista` <> '0000-00-00' SELECT t1.`id_plano`,         t1.`atividade`,         t1.`data_prevista`  FROM   `new_pae` AS t1  WHERE  t1.`id_user` = '$idUser'         AND t1.`data_prevista` <= Curdate()         AND t1.`data_prevista` <> '0000-00-00'         AND ( t1.`realizado` IS NULL                OR Length(t1.`realizado`) = 0 )
  5. benanamen's post in Stop submit if function returns false was marked as the answer   
    You might want to just use a date-picker that will put the date format you want into a read only field. Dont allow the user to enter it wrong in the first place.
  6. benanamen's post in database design was marked as the answer   
    You can have millions of records in a table. You should first learn Database Normalization and you will have a better idea how to do your tables. The amount of records you have wont even tickle a database.
  7. benanamen's post in Having Problem Populating a Select/drop down menu Using Data from a MySQL table was marked as the answer   
    Ok, looka here young man, see what you did?
     
    $row2 = mysql_fetch_array($r2, MYSQLI_ASSOC);    
     
    You do remember you are using Mysqli right?
     
     
    I think we should get you on PDO, it's just better. Not an opinion, it just is.
  8. benanamen's post in Submiting form with text fields and checkbox's Need help was marked as the answer   
    OP, so your not confused,
     
     
    $checkbox1 = isset($_POST['checkbox1']) ? 1 : 0;
     
    does the same exact thing as
     
     
     
    What I showed you is a Ternary Operator. It would behoove you to know how to use it. There is no need to have a value for the form check box.
     
    $checkbox1 = isset($_POST['checkbox1']) ? 'this_is_my_check_box_insert_value_not_a_number' : 0;
     
    A string will require to be quoted, a number no quotes.
  9. benanamen's post in var_dump(parse_url($url, PHP_URL_QUERY )) issue was marked as the answer   
    You dont use var_dump as part of your code. That is for debugging.
     
     
     
    Per the manual:
    var_dump — Dumps information about a variable
     
     
     
      $email = 'email@email.com';   echo $key = sha1($email.'my_super_duper_secret_sauce_here'.microtime());    // YOU HAVE TO DO THIS IN THE BROWSER. You also need to save the key to a DB. The key constantly changes so you cant compare what is generated directly. It will NEVER match. //https://www.mysite.com?k=0281cdeb4fa63c4ca087e8052b0c1685fc0a51e6   if ($key_from_db==$_GET['k']){ echo 'Match'; } else { echo 'No Match'; }
  10. benanamen's post in Set Status Code Header(401) and Apache ErrorDocument Help was marked as the answer   
    Try this:
    if($adminString == "False"){ die(header("Location: /path_to_file/error.php")); } Another thing you could do is just redirect them back to your main page and not even show an error to the user.
  11. benanamen's post in read a cvs file and only displaying some data was marked as the answer   
    I will leave it up to you to handle the dates
     
     
    <?php $url  = "http://ichart.finance.yahoo.com/table.csv?s=f"; $file = file($url); foreach ($file as $value)     {     if (stristr($value, '2015-09-10'))         {         echo $value;         }     } ?>
  12. benanamen's post in imploding a multi dimensional array was marked as the answer   
    $cars = array ( array("Volvo",22,18), array("BMW",15,13), array("Saab",5,2), array("Land Rover",17,15) ); function r_implode( $glue, $pieces ) { foreach( $pieces as $r_pieces ) { if( is_array( $r_pieces ) ) { $retVal[] = r_implode( $glue, $r_pieces ); } else { $retVal[] = $r_pieces; } } return implode( $glue, $retVal ); } echo r_implode( '||', $cars ) Result: Volvo||22||18||BMW||15||13||Saab||5||2||Land Rover||17||15
     
    Source:http://www.craiglotter.co.za/2010/04/09/php-implode-a-multi-dimensional-array/
×
×
  • 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.