Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    problemi con un ciclo if

    ciao a tutti

    sono abbastanza nuovo nella programmazione in generale..
    In questo codice php ho un problema legato al ciclo if che c'è alla fine.
    In pratica è come se l'if non ci fosse! anche se la condizione if ($runNum == $run_number) è verificata, l'istruzione query che sta nell'else viene comunque eseguita!
    Grazie in anticipo per le risposte


    <html>

    <title>ORQUAM</title>
    <h1 align="center">Offline Run QUAlity Monitor</h1>

    <body bgcolor="gray">

    <h2 align="center"> Cosmics </h2>




    <a href="http://193.205.71.152/orquam/cosmics_web.html">
    Back</a>-
    <a href="http://193.205.71.152/orquam/quality3_web.html">
    Home</a>
    </p>




    <form name="input" action="http://193.205.71.152/orquam/insertRun2.php" method="get">
    run number:
    <input name="run#" type="text">


    period:
    <input name="period" type="text"></p>


    B filed:
    <input name="Bfield" type="text"></p>


    events:
    <input name="events" type="text"></p>


    acorde:
    <input name="acorde" type="text"></p>


    hmpid:
    <input name="hmpid" type="text"></p>


    mtrg:
    <input name="mtrg" type="text"></p>


    mtrk:
    <input name="mtrk" type="text"></p>


    sdd:
    <input name="sdd" type="text"></p>


    spd:
    <input name="spd" type="text"></p>


    ssd:
    <input name="ssd" type="text"></p>


    t0:
    <input name="t0" type="text"></p>


    trd:
    <input name="trd" type="text"></p>


    tpc:
    <input name="tpc" type="text"></p>


    v0:
    <input name="v0" type="text"></p>


    pmd:
    <input name="pmd" type="text"></p>


    phos:
    <input name="phos" type="text"></p>


    trigger1:
    <input name="trg1" type="text"></p>


    trigger2:
    <input name="trg2" type="text"></p>


    trigger3:
    <input name="trg3" type="text"></p>


    trigger4:
    <input name="trg4" type="text"></p>


    trigger5:
    <input name="trg5" type="text"></p>


    trigger6:
    <input name="trg6" type="text"></p>
    <input value="Search" type="submit">
    </form>
    </p>

    <?php

    include 'orquam_config.php';
    include 'opendb.php';

    $runNum=$_REQUEST["run#"];
    $lhcAA=$_REQUEST["period"];
    $B=$_REQUEST["Bfield"];
    $esds;
    $eve=$_REQUEST["events"];
    $aco=$_REQUEST["acorde"];
    $highmpid=$_REQUEST["hmpid"];
    $mtrg=$_REQUEST["mtrg"];
    $mtrk=$_REQUEST["mtrk"];
    $sdriftd=$_REQUEST["sdd"];
    $spixeld=$_REQUEST["spd"];
    $sstripd=$_REQUEST["ssd"];
    $tzero=$_REQUEST["t0"];
    $transradd=$_REQUEST["trd"];
    $timeprojc=$_REQUEST["tpc"];
    $vzero=$_REQUEST["v0"];
    $pd=$_REQUEST["pmd"];
    $photons=$_REQUEST["phos"];
    $trg1=$_REQUEST["trg1"];
    $trg2=$_REQUEST["trg2"];
    $trg3=$_REQUEST["trg3"];
    $trg4=$_REQUEST["trg4"];
    $trg5=$_REQUEST["trg5"];
    $trg6=$_REQUEST["trg6"];

    //echo $runNum;
    //echo $lhcAA;

    $query = "select run_number from runsList";

    $result = mysql_query($query);

    while(list($run_number) = mysql_fetch_array($result))
    {
    if ($runNum == $run_number)
    echo 'run already in the database';
    else
    {
    $query = "INSERT INTO runsList (run_number, period, Bfield, ESDs, Events, acorde, hmpid, muon_trg, muon_trk, sdd, spd, ssd, t0, trd, tpc, v0, pmd, phos, trigger1, trigger2, trigger3, trigger4, trigger5, trigger6, jolly) VALUES ('$runNum','$lhcAA','$B','$esds','$eve','$aco','$h ighmpid','$mtrg','$mtrk','$sdriftd','$spixeld','$s stripd','$tzero','$transradd','$timeprojc','$vzero ','$pd','$photons','$trg1','$trg2','$trg3','$trg4' ,'$trg5','$trg6','Null')";

    $result = mysql_query($query);
    }

    }
    ?>

    </html>

  2. #2
    Aggiungi le parentesi qui

    if ($runNum == $run_number){
    echo 'run already in the database';
    }else
    {

    e ti consiglio di cambiare il nome qui

    <input name="run#" type="text">

    togliendo il cancelletto #

    ciao

  3. #3
    Aggiungi le parentesi qui

    if ($runNum == $run_number){
    echo 'run already in the database';
    }else
    è indefferente mettere le parentesi se è una sola riga, infatti mettendole non cambia niente..

    inserendo un echo $run_number nel ciclo while che segue il mysql_fetch_array, ho notato che non mi sputa fuori i valori di run_number che stanno nella tabella.
    Quindi il problema è sicuramente legato a questo, ma non riesco a spiegarmi perchè a ciò accade!

    grazie comunque
    ciao

  4. #4
    giusto per qualcuno che fosse interessato..

    ho sostituito l'ultima parte con questa:
    ....
    $query = "select count(run_number) as numrows from runsList where run_number='$runNum'";

    $result = mysql_query($query);

    while(list($numrows) = mysql_fetch_array($result))
    {
    //echo $numrows;

    if ($numrows != 0)
    echo 'run already in the database';

    else
    {
    $query = "INSERT INTO runsList (run_number, period, Bfield, ESDs, Events, acorde, hmpid, muon_trg, muon_trk, sdd, spd, ssd, t0, trd, tpc, v0, pmd, phos, trigger1, trigger2, trigger3, trigger4, trigger5, trigger6, jolly) VALUES ('$runNum','$lhcAA','$B','$esds','$eve','$aco','$h ighmpid','$mtrg','$mtrk','$sdriftd','$spixeld','$s stripd','$tzero','$transradd','$timeprojc','$vzero ','$pd','$photons','$trg1','$trg2','$trg3','$trg4' ,'$trg5','$trg6','Null')";

    $result = mysql_query($query);
    }
    }
    ?>

    </html>
    il problema era la query e l'if contenuto nel ciclo while....
    inserendo una query più intelligente si semplifica tutto..

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.