viernes, 27 de diciembre de 2024

select

 #!/usr/bin/php -q


<?php


// Include external configuration and helper files

require("/root/fm/db_con.php");     // Database connection details


// Establish a connection using MySQLi (object-oriented style)

$conn = new mysqli($host, $user, $password, $database);


// Check if the connection was successful

if ($conn->connect_error) {

    die("Connection failed: " . $conn->connect_error);

}


// Define the query to fetch leads

$query = "SELECT lead_id, phone FROM leads";


// Execute the query and check for errors

if ($result = $conn->query($query)) {

    

    // Check if there are any rows returned

    if ($result->num_rows > 0) {

        // Loop through the result set and output each row

        while ($row = $result->fetch_assoc()) {

            // Safely output the values (HTML escaped for safety)

            echo htmlspecialchars($row['lead_id']) . ", " . htmlspecialchars($row['phone']) . "\n";

        }

    } else {

        // If no rows were found

        echo "No records found.\n";

    }


    // Free result set to free up memory

    $result->free();

} else {

    // If query fails, output an error message

    echo "Error executing query: " . $conn->error . "\n";

}


// Close the database connection

$conn->close();


?>


miércoles, 25 de diciembre de 2024

php tenary operator logical opertor

 echo $cmd=(45>13 && 211<100 ?"AMBIORIX":"RODRIGUEZ");

 as only  1  of the condition is true will return RODRIGUEZ



 echo $cmd=(45>13 || 211<100 ?"AMBIORIX":"RODRIGUEZ");

in tis case will return AMBIORIX as at least 1  is true

----------------------------------------


$argv=[1,3];


 echo $var=(count($argv)!=2)?exit():1;

miércoles, 18 de diciembre de 2024

accesing to a multidimensional array value

,<?php


   $array = array(

    "foo" => "bar",

    42    => 24,

    "multi" => 

  array(

         "dimensional" => array(

             "array" => "foo"

         )

     ));



echo $array['multi']['dimensional']['array'];  //foo


?>

Other example



$i=1; 

  $pos=array();

 


  

   $pos[$i]=["familyId"=>"12","familylocalName"=>"Ambiorix"];



  //$pos[1] is an array so you can  access direct to is key value $pos[1]['familyId']; 



echo  $pos[1]['familyId'];

///

jueves, 5 de diciembre de 2024

applying a call back function to all keys on an array.

 $array1 = array('blue'  => 1, 'red'  => 2, 'green'  => 3, 'purple' => 4);


$array2 = array('green' => 3, 'blue1' => 1, 'yellow' => 7, 'cyan'   => 8);



function test($n,$search_array){

return  array_key_exists($n, $search_array); 

}



echo "<br>";

print_r(array_map('strtoupper',array_keys($array1)));  

// will print Array ( [0] => BLUE [1] => RED [2] => GREEN [3] => PURPLE )


echo "<br>";


echo test('yellow',$array2);   //  echo 1