Please i am working on a project and need to generate pincode per request. This is the script i have for php but i need to implement codeigniter 3. Also please can i set it in such a way that if i want 10 pin i input 10 and generate 10 into the database and if want 50 i input 50. i am new to codeigniter 3 and i have read the tutorials but doesnt seems to help on this.
Here is my code on php
Please i want to be able to generate base on the number i want per request.
<?php
$connect = mysqli_connect("localhost","hadassa","root", "")
or die("Cannot connect");
$digits = 5;
function gen_ran($digits) {
$n = "";
for ($x = 1; $x <= $digits; $x++) {
$n.=mt_rand(0,9);
}
return $n;
}
function gen_ran2($digits)
{
$n2 = "";
for($a=1; $a<=$digits; $a++)
{
$n2 .=mt_rand(0,9);
}
return $n2;
}
for($a=1; $a<=20; $a++)
{
$codes = gen_ran($digits) . gen_ran2($digits);
$query = "INSERT INTO pin (pin)
VALUES ('$codes')";
$result = mysqli_query($connect, $query)
or die("Error");
if($result)
echo"$codes<br>";
}
?>
<script type="text/javascript">
alert("PIN Generated Successfully");
window.location = "#";
</script>
codeignater use the MVC So
create a controller in controller folder to write logic
create a model in models folder for write database code
in the viewer, folder create a view for the user view code
https://www.youtube.com/watch?v=K71j-rWXejk&index=2&list=PLUpnKy5Si8zDouvZiUMHwSSyVrowJmH22
https://www.youtube.com/watch?v=IOZqRgOgSu4
Related
I have a code that is used for adding a channel to an IPTV platform!
Currently we have the option to put a channel in single category/genre... What we want to do is instead of this drop box to a have something like checklist or space to write the genres/categories... I have tried everything I remembered I knew, but nothing worked! Thank you
function get_genres() {
global $tv_genre_id;
$genres = Mysql::getInstance()->from('tv_genre')->get()->all();
$option = '';
foreach ($genres as $arr){
$selected = '';
if ($tv_genre_id == $arr['id']){
$selected = 'selected';
}
$option .= "<option value={$arr['id']} $selected>"._($arr['title'])."\n";
}
return $option;
}
I made a module that display how many days ago a article was published
it looks like this.
{source}
<?php
$jinput = JFactory::getDocument()->input;
$option = $jinput->get('option');
$view = $jinput->get('view');
if ($option=="com_content" && $view=="article") {
$ids = explode(':',JRequest::getString('id'));
$article_id = $ids[0];
$article =& $jinput->get("content");
$article->load($article_id);
$date = new JDate($article->get("publish_up"));
$currentTime = new JDate('now');
$interval = $date->diff($currentTime);
if($interval->d == 0) {
echo 'dzisiaj' . "<br>";
}
else if( $interval->d == 1) {
echo 'wczoraj' . "<br>";
}
else if( $interval->d > 1) {
echo $interval->format('%a dni temu') . "<br>";
}
}
?>
{/source}
And it works on my local joomla but when use it on custom template it doesnt work. I'm using Joomla 3.4.8.
The issue is you're trying to access the input values using Document Factory that's wrong you have to use
$jinput = JFactory::getApplication()->input;
Document Factory is used for other purpose like adding , styles or Js to the pages etc. read more about input here.
Hope it make sense.
I am trying a file upload by drag and drop.For this ui side i have used blueimp file upload plugin and server side i am using the same upload.cgi that i am using for simple browse and file upload.Issue i am facing is in my main method of cgi hook method is not getting called :-
$cgi = CGI->new(\&hook, "file_upload");
here control is not going in hook method.
sub hook
{
&logMsg("In Hook1");
my ($name, $buffer, $bytesRead, $data) = #_;
&logMsg("In Hook");
&logMsg("name=$name,bytesRead=$bytesRead");
if (defined $lastSeenName)
{
if (($name ne $lastSeenName) || ($bytesRead < $lastSeenTotal))
{
$subTotal += $lastSeenTotal;
}
}
else
{
$uploadSize = $ENV{'CONTENT_LENGTH'};
&logPct(0);
}
$lastSeenName = $name;
$lastSeenTotal = $bytesRead;
$fileSizeMap{$name} = $bytesRead;
$totalBytes = $subTotal + $bytesRead;
if ($uploadSize > 0)
{
my $curPct = int((100 * $totalBytes)/$uploadSize);
$curPct = 98 if ($curPct > 98);
&logPct($curPct);
}
}
when i am using my using my old style browse and upload file hook method is getting called.Can anybody let me know in what i am missing and why hook method is not getting called.
Thanks,
Manish
I have got a machine (Debian based) with some temperature sensors attached to it, and i would like to query them over snmp, from one script. I can work with one sensor ok, but i am struggling when i plug another one in.
What I am trying to do is loop through each device, and give each one an id, then use this ID as part of the OID, then give it a value.
I've never worked with snmp before, and my perl is not great so any help would be much appreciated. Below is my code:
#!/usr/bin/perl
use NetSNMP::agent (':all');
use NetSNMP::ASN qw(ASN_OCTET_STR ASN_INTEGER);
$BASE_OID=".1.3.6.1.4.1.41050";
$dev_id=1;
$string_value;
$integer_value;
sub pimon_handler {
my ($handler, $registration_info, $request_info, $requests) = #_;
my $request;
my $oid_key;
for($request = $requests; $request; $request = $request->next()) {
$oid_key=$BASE_OID . '.' . $dev_id;
my $oid = $request->getOID();
if ($request_info->getMode() == MODE_GET) {
if ($oid == new NetSNMP::OID($oid_key . '.0')) {
$request->setValue(ASN_OCTET_STR, $string_value);
}
elsif ($oid == new NetSNMP::OID($oid_key . '.1')) {
$request->setValue(ASN_INTEGER, $integer_value);
}
} elsif ($request_info->getMode() == MODE_GETNEXT) {
if ($oid == new NetSNMP::OID($oid_key . '.0')) {
$request->setOID($oid_key . '.1');
$request->setValue(ASN_INTEGER, $integer_value);
}
elsif ($oid < new NetSNMP::OID($oid_key . '.0')) {
$request->setOID($oid_key . '.0');
$request->setValue(ASN_OCTET_STR, $string_value);
}
}
}
}
#location of where we are going to find the 1wire devices
#sensors = `cat /sys/bus/w1/devices/w1_bus_master1/w1_master_slaves`;
chomp(#sensors);
#loop through the sensors we find
foreach $line(#sensors) {
#work out the temp we have got. Need to change this for other sensor types
$output = `cat /sys/bus/w1/devices/$line/w1_slave`;
$output =~ /t=(?<temp>\d+)/;
$integer_value = sprintf "%.0f",$+{temp} / 1000;
$string_value = $line;
my $agent = new NetSNMP::agent();
$agent->register("Pimon$looptest", $BASE_OID . '.' . $dev_id,
\&pimon_handler);
print "Dev $dev_id temp $line temp is $integer_value\n";
$dev_id ++;
}
Are you getting any errors or output?
I suspect that your problem lies in and around your reading the data file by shelling-out to cat instead of opening the file and looping over the linewise contents.
Try dumping the value of #sensors. if it is a single entry array, with the only element containing your entire file, then simply switch #sensors to be scalar. then split $sensors into an array and loop over that.
my $sensors = `read something`
chomp $sensors;
my #sensors = split(/\n/, $sensors);
foreach $line (#sensors) {
...
Hi friends why mysqli one pulling one row with foreach loop in php ? Shouldn't it fetch arrays of all rows ?
$link = new mysqli(DB_SERVER, DB_USER,DB_PASSWORD,DB_NAME) or die('error connecting');
$mob = query("SELECT mobile FROM members_db");
foreach ($mob as $numbers){
$mob_numbers = $numbers['mobile'];
print_r($mob_numbers); exit();
}
You need to do the following
Change:
foreach ($mob as $numbers)
{
$mob_numbers = $numbers['mobile'];
print_r($mob_numbers); exit();
}
To
$results = array();
foreach ($mob as $numbers)
{
$results[] = $numbers['mobile'];
}
print_r($results); exit();
You have to 'Fetch' the records one by one
$mob = query("SELECT mobile FROM members_db");
while($row = mysqli_fetch_array($link, $mob)){
print_r($row['mobile'])
}
Also, not sure why you're calling exit() inside the loop. Doesn't make sense.
remove your exit(); within the loop