php-general Digest 3 Jul 2013 09:36:06 -0000 Issue 8282

Topics (messages 321518 through 321520):

Re: Problem with variables
        321518 by: Tamara Temple

Re: Reseting the auto-increment number in a MySQL database.
        321519 by: Tamara Temple

Hello again. new newbie querstion
        321520 by: Karl-Arne Gjersøyen

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
Fernando A <soporteallpurp...@gmail.com> wrote:
> I am working with php and codeigniter, but I have not yet experienced.
> I need create a variable that is available throughout  system.
> This variable contains the number of company and can change.
> as I can handle this?

Hi, Fernando, welcome. I'm just a little unsure what you mean by "number
of company" -- is this a count, as in 10 companies, or is it a phone
number, or is it something else?

Jim's reply is workable -- storing session values is quite useful, but
sessions are tied to a specific browser client/ip, and I'm not sure
that's what you want/need here.

If you are looking for setting a global variable that will be available
everywhere in your application, you can use $GLOBALS, or set it from the
very top level context of the application. Given you're using
CodeIgniter, which sadly I am not versed in, you may need to set it with
$GLOBALS: 

$GLOBALS['my_var'] = 10; // whatever you need to do here

When you say it changes, how and when exactly does it change?


--- End Message ---
--- Begin Message ---
Tedd Sperling <tedd.sperl...@gmail.com> wrote:
> On Jun 27, 2013, at 8:47 PM, Paul M Foster <pa...@quillandmouse.com> wrote:
> 
> > On Thu, Jun 27, 2013 at 11:47:28PM +0200, adriano wrote:
> > 
> >> holes in sequence of auto increment happen using transaction for
> >> insert new record but you don't commit transaction itself
> >> it seems that the autoincrement is incremented anyway
> >> at least this is my case.
> > 
> > I think what Tedd was referring to was something else. The "hole" was
> > quite large. I've seen this behavior myself, in PostgreSQL. From one
> > transaction to the next, there were over 10,000 skipped numbers, and
> > only me and my wife on the system. Some sort of bug, like a spinlock
> > that wasn't interrupted the way it should have been. I remember the
> > system taking forever to calm down before it gave the next transaction a
> > number way forward of the last one. I waited in front of my browser for
> > quite some time. But I couldn't explain why.
> > 
> > Paul
> 
> Yes, it was something like what Paul said -- it was not a transaction skip.
> 
> I don't know what to think about it -- no explanation.
> 
> But, the problem suddenly vanished -- very strange.
> 
> Cheers,
> 
> tedd
> 
> _____________________
> tedd.sperl...@gmail.com
> http://sperling.com

I have no answers as to why the huge skip forward, the huge skip
backwards though makes me think someone else is doing something in the
database, and all the alarums and red flags are waving. I hope I'm
wrong.

--- End Message ---
--- Begin Message ---
I have done as you explain for me an it works very vell in the halft part
of my application.
But below is my snippet of my source code where the number of items and
weight not will update itself.
This code do as what number I write in the "oppdater_stk_nonel_tenner[]"
field is written as result, instead of the calculated result.
I am also using var_dump() to check my viariables but there is something
here I have missed.

I hope it is ok to post my norwegian search code as an exaple. If this
source code is to difficult because of my long norwegian name (Description
of the meaning of varable) i will re-write it all in English as I appricate
your good advice and help!

Tanks.

// My form with array's
<input type="hidden" name="varenr[]" value="<?php echo "$varenr"; ?>"
    <input type="hidden" name="stk_pa_lager[]" value="<?php echo
"$stk_pa_lager"; ?>">
    <input type="hidden" name="kg_pa_lager[]" value="<?php echo
"$kg_pa_lager"; ?>">
    <input type="number" name="oppdater_stk_nonel_tenner[]" size="6">
<input type="hidden" name="valgt_lager" value="<?php echo "$valgt_lager";
?>">
    <input class="submitKnapp" type="submit" name="oppdater_nonel_tennere"
value="Neste">

if(isset($_POST['oppdater_nonel_tennere'])){
    $valgt_lager = $_POST['valgt_lager'];
    $varenr = $_POST['varenr'];
    $kg_pa_lager = $_POST['kg_pa_lager'];
    $stk_pa_lager = $_POST['stk_pa_lager'];
    $oppdater_stk_nonel_tenner = $_POST['oppdater_stk_nonel_tenner'];

include('../../tilkobling.php');

// count how many serialnumber it is the the array for use later in for
loop.
$antall_varenr = count($varenr);

    // Run for loop as long as $i is less than or equal to $antall_varenr.
    for($i=0;$i<$antall_varenr;$i++){

        // update amont in stock. Adding value of
$oppdater_stk_nonel_tenner[$i] to $stk_pa_lager
        $stk_pa_lager[$i] += $oppdater_stk_nonel_tenner[$i];

// Get new weight in kg in stock
        $kg_pa_lager =  $stk_pa_lager[$i] * 0.001;

    // Update the database table
    $sql = "UPDATE nonel_tennere SET stk_pa_lager = '$stk_pa_lager[$i]',
kg_pa_lager = '$kg_pa_lager' WHERE varenr = '$varenr[$i]' LIMIT 1";
    mysql_query($sql,$tilkobling) or die(mysql_error());
    var_dump($sql);
}
echo "<p><strong>Databasen er oppdatert</strong></p>";
?>
<form action="index.php" method="post">
<input type="hidden" name="valgt_lager" value="<?php echo "$valgt_lager";
?>">
<input type="hidden" name="admin_oppgave" value="vis_status">
<input class="submitKnapp" type="submit" name="velg_lager" value="Neste">
</form>



<?php
}
?>

I can't figure out why $stk_pa_lager[$i]; is the same as written in
$oppdater_stk_nonel_tennere[$i] as long I have us this += operator in

$stk_pa_lager[$i] += $oppdater_stk_nonel_tenner[$i];

I have just copy and past it from a working example above and chance the
table name and $oppdater_stk_nonel_tenner[$i] variable.

Thanks for your time.

Karl

--- End Message ---

Reply via email to