Jump to content

rugzo

Members
  • Posts

    87
  • Joined

  • Last visited

    Never

Posts posted by rugzo

  1. hi all,

     

    how can i sum the second value in a mysql field after the delimiter?

     

    assume i have a column-->

     

    xxx

    1_34

    34_3

    23_32

    ...

     

    i want to sum the value after the "_" delimiter...

     

    i tried like that but no success -->

     

    "select sum(substring_index('score','_',-1)) from udf...

  2. Hi,

     

    i have a row which should be updated by every query.

     

    id  sum

    0    1

     

    every time i run the query it should update the sum plus the new value.

     

    update x set sum = sum + $newvalue.

     

    this works fine.

     

    but how can i do that with explode. i need this because this column has to values which are seperated with "_".

    like 120_140.

    is it possible with sql query that i can do that.

     

    as example the current values are

     

    120_140

     

    the new values are 10_5

     

    = 120+10_140+5

    130_145

    ?

     

    i know i can do that with php easyly but it must be done via the sql query in my structure ?

     

    thanks...

  3. Hi,

     

    if i execute this command -->

    $query= mysql_query("ALTER TABLE `ana` DROP COLUMN `sdfsd`");

     

    it drops the column but gives me the error -->

     

    Unknown column 'sdfsd' in 'ana'

     

    Has anyone a clue why i get this error even it drops the column??

  4. Hi all,

     

    i built an interface which produces forms and near by also the sql databases for the forms. The forms have categories and items. My problem is when its build the form i can not relate the items to the categories. example-->

    cars 

      ford 

      bmw

    motors 

      yamaha 

      honda 

    ...

     

    lets assume i built this form which also built the database. The database looks then like this-->

     

    id cars ford bmw motors yamaha honda

     

    if the order would never change i would have no problem but if i add or remove items and categories via the interface after i built the form it will add them after the last column. If i would now add another car it would it put after the last item "honda". I have only 2 chances.

     

    a) is it possible to tell sql that ford and bmw are the items of the category car?

    b) as my interface works dynamically and in a specific order it could change the order again after i submit the changes. If you add an item you have the possibility to say after which column ---> ALTER TABLE `test`.`yeni1` ADD COLUMN `df` VARCHAR(45) NOT NULL AFTER `kkkk`;...

    Is there also a command which updates the please of the field?

     

    one of them could solve my problem, please help...

     

    thanks in advance...

  5. Thanks for the reply.

     

    Assume i have a table in mysql like -->

     

    id  inputvolume  name 

    0    5              john

    1    4              mike

    2    3              john

    3    5              mike

    ...

     

    and i have a page which should connect to database and read it-->

     

    name    volume

    john      echo ...

    mike      echo...

     

    how can i do that the page will connect to database and read the data?

    don't misunderstand me, i can make the connection via php and read the data this is no problem via ususal meta refresh but i don't have a clue how its done via ajax...

  6. Hi All,

     

    for every person the page should get data from mysql and display it on the page without any onchange, onclick or input... i have a form where persons make entries which are submitted to mysql and i want to see them all in another page. So it simply will get data from mysql every second without f5.

     

    is this possible and can you give me a lead?

     

    thanks...

  7. ok i got it :)

     

    <code><html>

    <head>

    <script language="JavaScript">

     

    <!--

     

     

    var clockID = 0;

    var saniye = 00;

    var dakika = 00;

    var saat = 00;

     

    function UpdateClock() {

     

    if(clockID) {

    clearTimeout(clockID);

    clockID = 0;

    }

     

    saniye ++;

    if(saniye <= 9)

    {

    var saniye_yaz = "0" + saniye ;

    }else{

    var saniye_yaz = saniye ;

    }

     

    if (saniye > 59)

    {

    dakika ++;

    saniye = 0;

    saniye_yaz ="00";

    }

     

    if(dakika <=9)

    {

    var dakika_yaz = "0" + dakika ;

    }else{

    var dakika_yaz = dakika ;

    }

     

     

     

    if(dakika > 59)

    {

    saat ++;

    dakika = 0;

    dakika_yaz = "00";

    }

     

    if(saat <=9)

    {

    var saat_yaz = "0" + saat ;

    }else{

    var saat_yaz = saat ;

    }

     

    if(saat>=24)

    {

    saat=0;

    dakika=0;

    saniye=0;

    }

    document.theClock.theTime.value = saat_yaz + ":" + dakika_yaz + ":" + saniye_yaz;

    document.title = saat_yaz + ":" + dakika_yaz + ":" + saniye_yaz;

    clockID = setTimeout("UpdateClock()", 1000);

    }

     

     

    function StartClock() {

    clockID = setTimeout("UpdateClock()", 500);

    }

     

    function KillClock() {

    if(clockID) {

    clearTimeout(clockID);

    clockID = 0;

    }

    }

     

    //-->

     

    </script>

    </head>

    <body onLoad="StartClock()" onUnload="KillClock()">

    <center>

    <form name="theClock"><input name="theTime" size="8" type="text">

    </form>

    </center>

    </body>

    </html></code>

     

  8. Hi All,

     

    i have a code which shows the clock. But i want to use it as a counter like a kronometre. It simply will start to count from zero if the page is refreshed. That i managed but i couldn't make it to count from zero.

    I know that something like below

     

    x = new date() ; y = new date(), start = x - y... but couldn't do it since my java knowledge is not enough. I will implement this into my php page. Can someone please help. It just has to start from 00:00:00

     

     

     

    <html>

    <head>

    <script language="JavaScript">

     

    <!--

     

     

    var clockID = 0;

     

    function UpdateClock() {

    if(clockID) {

    clearTimeout(clockID);

    clockID = 0;

    }

     

    var tDate = new Date();

     

    if((tDate.getSeconds())<=9)

    {

    document.theClock.theTime.value = ""

    + tDate.getHours() + ":"

    + tDate.getMinutes() + ":0"

    + tDate.getSeconds();

    document.title = "The time is: "

    + tDate.getHours() + ":"

    + tDate.getMinutes() + ":0"

    + tDate.getSeconds();

    } else if((tDate.getMinutes())<=9) {

    document.theClock.theTime.value = ""

    + tDate.getHours() + ":0"

    + tDate.getMinutes() + ":"

    + tDate.getSeconds();

    document.title = "The time is: "

    + tDate.getHours() + ":0"

    + tDate.getMinutes() + ":"

    + tDate.getSeconds();

    } else if(((tDate.getSeconds())<=9) && ((tDate.getMinutes())<=9)) {

    document.theClock.theTime.value = ""

    + tDate.getHours() + ":0"

    + tDate.getMinutes() + ":0"

    + tDate.getSeconds();

    document.title = "The time is: "

    + tDate.getHours() + ":0"

    + tDate.getMinutes() + ":0"

    + tDate.getSeconds();

    } else {

     

     

    document.theClock.theTime.value = ""

    + tDate.getHours() + ":"

    + tDate.getMinutes() + ":"

    + tDate.getSeconds();

    document.title = "The time is: "

    + tDate.getHours() + ":"

    + tDate.getMinutes() + ":"

    + tDate.getSeconds();

    }

     

    clockID = setTimeout("UpdateClock()", 1000);

    }

    function StartClock() {

    clockID = setTimeout("UpdateClock()", 500);

    }

     

    function KillClock() {

    if(clockID) {

    clearTimeout(clockID);

    clockID = 0;

    }

    }

     

    //-->

     

    </script>

    </head>

    <body onload="StartClock()" onunload="KillClock()">

    <center>

    <form name="theClock"><input name="theTime" size="8" type="text">

    </form>

    </center>

    </body>

    </html>

     

  9. Sorry i didn't exactly understand what you mean with code tags but i will put in the whole php part. But basically this is a setup interface. On the top you select forms which you also build at that time dinamically. You have a main category. Each main category is a form. If you build a main category you will also build the whole form. You have to build the subcategories which also have items. All of them are inputs. the subcategories connected to the same main categories have to have a total point of 100, and the items connected to the same sub categories have to have the also 100 points together. I will copy paste the middle part of my code which builds the form. If its not enough i can paste the whole code.

     

     

    <?php

     

    $names = $_GET['cat'].$catname1;

     

    //form input ids

     

    $mainid = "mainid00" ;

    $mainname = "mainname00" ;

    $subname = "subname00" ;

    $itemname = "itemname00" ;

    $subid = "subid00" ;

    $itemid = "itemid00" ;

    $sublp = "subloc00" ;

    $subgp = "subgl00" ;

    $itemlp = "itemlp00" ;

    $itemglp = "itemglp00" ;

    $itemlnc = "itemlnc00" ;

    $itemgnc = "itemgnc00" ;

    $gzero = "gzero00" ;

    $lzero = "lzero00" ;

    $glac = "glac00" ;

    $locac = "locac00" ;

    $descr = "descr00" ;

    $mdelet = "mdelet00" ;

    $sdelet = "sdelet00" ;

    $idelet = "idelet00" ;

    $sturn = 0 ;

    $iturn = 0 ;

     

    //ana kategori

    $sqlm = mysql_query("select * from qasetup where cattype='main' and catname='$names'");

     

    echo "<table border='1'>

          <tr>

          <tr><td colspan='1'><font size='5'><b><center>Name Setup</center></b></font></td>

          <td colspan='6'><font size='5'><b><center>Point Setup</center></b></font></td>

          <td colspan='5'><font size='5'><b><center>Main Setup</center></b></font></td></tr>" ;

     

    while($m = mysql_fetch_array($sqlm)){

     

        $mcat = $m[catname] ;

        $mtype = $m[cattype] ;

     

     

        echo "<tr><td><input type='hidden' name='".$mainid."' value='".$m[id]."'><input type='text'

        name='".$mainname."' value='".$mcat."'></td><td></td><td></td><td></td>

        <td></td><td></td><td></td><td></td><td></td><td></td></td>

        <td></td>

        <td>delete<input type='checkbox' name='".$mdelet."'></td></tr><br><br>";

     

        $mname = $_POST[$mainname] ;

     

        if($_POST[$mdelet]){

     

          $idmm = $_POST[$mainid] ;

     

     

            $sqlsdelete = mysql_query("delete from qasetup where id = '$idmm'") or die (mysql_error());

            $sqlsdelet = mysql_query("delete from qasetup where parent = '$mcat'") or die (mysql_error());

     

          }

     

     

    //subkategori

     

          $sqls = mysql_query("select * from qasetup where parent = '$mcat' and cattype = 'sub'");

            while($s = mysql_fetch_array($sqls)){

     

        //check global local

          $sloc = $s[loc];

          $sglob = $s[glob];

     

          if($sloc == 0){

            $lsusage = 'disabled';

          }else{$lsusage = 'enabled';}

          if($sglob == 0){

            $gsusage= 'disabled';

          }else{$gsusage = 'enabled';}

     

              $scat = $s[catname];

              echo "<tr><td><input type='hidden' name='".$subid."' value='".$s[id]."'>     

              <input type='text' name='".$subname."' value='".$scat."'></td>

              <td>    <font size='2'> LP :<input type='text' name=".$sublp." size='2' value='".$s[lp]."' ".$lsusage."></td>

              <td>  GP :<input type='text' name=".$subgp." size='2' value='".$s[gp]."' ".$gsusage.">

              </font></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>

              <td>delete<input type='checkbox' name='".$sdelet."'<br><br></td></tr>";

     

    $sname = $_POST[$subname] ;

     

      if($_POST[$sdelet]){

     

          $ids = $_POST[$subid] ;

          $sname = $_POST[$subname] ;

     

            $sqlsdelete = mysql_query("delete from qasetup where id = '$ids'") or die (mysql_error());

            $sqlsdelet = mysql_query("delete from qasetup where subparent = '$sname' and

    parent = '$mcat' and cattype ='item'") or die (mysql_error());

     

          }

     

     

          //check

     

     

      if($sname != $s[catname] and $s[cattype] == 'sub' and $s[parent] == $mname){

     

      $sqlsubnamecheck = mysql_query("select * from qasetup where cattype = 'sub'

      and parent = '$mname'");

     

        while($snamecheck = mysql_fetch_array($sqlsubnamecheck)){

          if($sname == $snamecheck[catname]){

     

     

          $sname = $s[catname] ;

          echo "<META HTTP-EQUIV='Refresh' CONTENT='0;URL=http://localhost/xraytest/qa/qasetup.php?cat=$mname&cmd1=error1'>";

            }

                }

                    }

     

     

            //endcheck

     

     

    if($_POST['gonder']){

    $sqle = mysql_query("update qasetup set subparent = '$sname'

    where subparent = '$scat' and parent = '$mcat' and cattype ='item'") or die (mysql_error());

     

    $ids = $_POST[$subid] ;

     

     

    $slp = $_POST[$sublp] ;

    $sgp = $_POST[$subgp] ;

     

    $sql = mysql_query("update qasetup set lp = '$slp', gp = '$sgp', catname = '$sname'

    where id = '$ids'") or die (mysql_error());

      }

              $sdelet++ ;

              $subname++ ;

              $subid++ ;

              $sublp++ ;

              $subgp++ ;

              $sturn++ ;

     

     

     

     

    //item

     

              $sqlimis = mysql_query("select * from qasetup where parent = '$mcat' and subparent = '$scat' and cattype = 'item'");

        while($it = mysql_fetch_array($sqlimis)){

     

          //check global local

          $itl = $it[loc];

          $itg = $it[glob];

     

          if($itl == 0){$lusage = 'disabled';}else{$lusage = 'enabled';}

          if($itg == 0){$gusage = 'disabled';}else{$gusage = 'enabled';}

     

          if($itl == 1){$locacpa = 'checked';}else{}

          if($itg == 1){$glacpa = 'checked';}else{}

     

          if($it[lzero]==1){$llzero = 'checked';}else{$llzero = '';}

          if($it[gzero]==1){$ggzero = 'checked';}else{$ggzero = '';}

     

              $icat = $it[catname];

      $comment = $it[description];

              echo "<tr><td><input type='hidden' name='".$itemid."' value=".$it[id]."><a onMouseOver=doalt('".$comment."')

              onMouseOut=realt()>     

                       <input type='text' name='".$itemname."' value='".$icat."'</a></td>

              <td>    <font size='2'>

              LP :<input type='text' name='".$itemlp."' size='1' value='".$it[lp]."' ".$lusage."></td><td>

                LNC :<input type='text' name='".$itemlnc."' size='1' value='".$it[lnc]."' ".$lusage."></td><td>

                LZero :<input type='checkbox' name='".$lzero."' ".$llzero."  ".$lusage."></td><td>  

                 GP :<input type='text' name='".$itemglp."' size='1' value='".$it[gp]."' ".$gusage."></td><td>

                 GNC :<input type='text' name='".$itemgnc."' size='1' value='".$it[gnc]."' ".$gusage."></td><td>

                GZero :<input type='checkbox' name='".$gzero."' ".$ggzero." ".$gusage."></font><br></td>

              <td>Description:<input type='text' name='".$descr."' value='".$comment."'></td><td></td>

              <td>local<input type='checkbox' name='".$locac."' ".$locacpa.">

                      global<input type='checkbox' name='".$glac."' ".$glacpa."></td>

              <td></td>

              <td>delete<input type='checkbox' name='".$idelet."'><br><br></td></tr>";

     

     

          if($_POST[$idelet]){

     

          $idi = $_POST[$itemid] ;

     

            $sqlidelete = mysql_query("delete from qasetup where id = '$idi'") or die (mysql_error());

     

          }

     

              if($_POST['gonder']){

    $itemna = $_POST[$itemname] ;

    $idi = $_POST[$itemid] ;

    $itlp = $_POST[$itemlp] ;

    $itgp = $_POST[$itemglp] ;

    $itlnc = $_POST[$itemlnc] ;

    $itgnc = $_POST[$itemgnc] ;

    $desc = $_POST[$descr] ;

     

    if($_POST[$gzero]){$itgz=1;}else{$itgz=0;}

    if($_POST[$lzero]){$itlz=1;}else{$itlz=0;}

    if($_POST[$glac]){$gac=1;}else{$gac=0;}

    if($_POST[$locac]){$lac=1;}else{$lac=0;}

     

    //check

     

     

      if($itemna != $it[catname] and $it[cattype] == 'item' and $it[parent] == $mname and $it[subparent] == $sname){

     

      $sqlitemnamecheck = mysql_query("select * from qasetup where cattype = 'item'

      and parent = '$mname' and subparent = '$sname'");

     

        while($inamecheck = mysql_fetch_array($sqlitemnamecheck)){

          if($itemna == $inamecheck[catname]){

     

     

          $itemna = $it[catname] ;

          echo "<META HTTP-EQUIV='Refresh' CONTENT='0;URL=http://localhost/xraytest/qa/qasetup.php?cat=$mname&cmd=error'>";

            }

                }

                    }

     

     

            //endcheck

     

    $sqli = mysql_query("update qasetup set lp = '$itlp', gp = '$itgp', lnc = '$itlnc', gnc = '$itgnc',

    lzero ='$itlz', gzero = '$itgz', loc = '$lac', glob = '$gac', description = '$desc', catname = '$itemna'

    where id = '$idi'") or die (mysql_error());

     

            }

              $idelet++ ;

              $itemname++ ;

              $itemid++ ;

              $itemlp++ ;

              $itemglp++ ;

              $itemlnc++ ;

              $itemgnc++ ;

              $gzero++ ;

              $lzero++ ;

              $itemlnc++ ;

              $itemgnc++ ;

              $glac++ ;

              $locac++ ;

              $descr++ ;

              $iturn++ ;

     

     

        }

            }

    }

     

     

     

     

     

    ?>

  10. I have forgotten to mention that i have one form with two seperate inputs. So i cannot simply get all the inputs. Its something like half of the inputs have ids with even and the other half with odd numbers and i have to get them into two diffrent codes like above and send them that way.

  11. Hi All,

     

    i want to use ajax in my php page. Here is what i have* --->

     

    <script language="javascript" type="text/javascript">
    
          <!--
    
          // Get the HTTP Object
    
          function getHTTPObject(){
    
          if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
    
          else if (window.XMLHttpRequest) return new XMLHttpRequest();
    
          else {
    
          alert("Your browser does not support AJAX.");
    
          return null;
    
          }
    
          }
    
    
    
          // Change the value of the outputText field
    
          function setOutput(){
    
          if(httpObject.readyState == 4){
    
          document.getElementById('outputText').value = httpObject.responseText;
    
          }
    
    
    
          }
    
    
    
          // Implement business logic
    
          function doWork(){
    
          httpObject = getHTTPObject();
    
          if (httpObject != null) {
    
          httpObject.open("GET", "upperCase.php?inputText="
    
          +document.getElementById('inputText').value, true);
    
          httpObject.send(null);
    
          httpObject.onreadystatechange = setOutput;
    
          }
    
          }
    
    
    
          var httpObject = null;
    
    
    
          //-->
    
          </script>
    
    
    
          <form name="testForm">
    
          Input text: <input type="text" onkeyup="doWork();" name="inputText" id="inputText" /> <br>
    
          Output text: <input type="text" name="outputText" id="outputText" />
    
          </form>
    

     

    This sends the input to my other php page and returns the calculated data back. But my problem is i have multiple fields in a form which is also created dynamicallly. How can i get the datas from multiple fields and not only one specific.

     

     

    Thanks...

     

     

     

     

  12. Hi,

     

    i have 2 tables like

     

    tableincoming

     

    id name      posts    time

    1 john        5          2009-07-01

    2 mike        3          2009-07-02

    3 john        2          2009-07-03

    4 elise        2          2009-07-05

    5 stephan    1        2009-07-02

    6 john          2        2009-07-08

    7 elise        2          2009-07-10

    ...

     

    if i want to group and count the posts in time order, it works fine. It's like this  ->

     

    $sqli = mysql_query("SELECT  sum(if(posts!='' and time like 2009-7%,1,0)) as donet,name,time from tableincoming group by name") ;

     

    But i have another table for outgoing like this -->

     

    tableoutgoing

     

    id name      outposts    time

    1  mike        5          2009-07-03

    2  mike        3          2009-07-02

    3 john        2          2009-07-03

    4 john        2          2009-07-01

    5 stephan    1        2009-07-02

    6 john          2        2009-07-02

    7 elise        2          2009-07-10

    ...

     

    This is just a simple example, the original tables are much more complex. But what i am trying to do is to calculate how many incoming and outgoing post they have per name in one query. I tried many ways but it didn't worked. At the end it should look like below:

     

    name    posts  outposts    time

    mike        3        5          2009-july

    john          4          2          2009-july

    stephan      3        1        2009-july

    elise            5      2          2009-july

    ...

     

    i tried several thing like -->

    $sqli = mysql_query("SELECT tableincoming, sum(if(tableincoming.posts !='' and tableincoming.time like '2009-7%',1,0)) as donet,

    tableoutgoing.outposts, sum(if(tableoutgoing.outposts='' and tableoutgoing.time like '2009-7%',1,0)) as done from tableincoming left join tableoutgoing on tableoutgoing.name = tableincoming.name group by tableincoming.name");

     

    Can anyone help?

     

     

    Thanks...

     

  13. Hi all,

     

    i have a question about multiple counts in one query, i searched a lot and understood that its possible but didn't succeed.

     

    $sql = mysql_query("SELECT count(gender) FROM nsnag WHERE gender = 'male' ") ;

    $sql = mysql_query("SELECT count(gender) FROM nsnag WHERE gender = 'female' ") ;

     

    Can i mix them up in one query like

     

    $sql = mysql_query("SELECT count(if(gender=male)) as male, count(if(gender=female)) as female FROM nsnag ") ;

     

    thanks...

     

     

     

  14. Hi all,

     

    i have a problem by date calculation.

     

    $buayisim2 = date('M-Y',mktime(0,0,0,date("m")-2)) ;

    $buayisim3 = date('M-Y',mktime(0,0,0,date("m")-3)) ;

    $buayisim4 = date('M-Y',mktime(0,0,0,date("m")-4)) ;

    $buayisim5 = date('M-Y',mktime(0,0,0,date("m")-5)) ;

    $buayisim6 = date('M-Y',mktime(0,0,0,date("m")-6)) ;

     

    the above code works fine except $buayisim4.

     

    $buayisim2 reproduces Apr-2009

    $buayisim3 reproduces Mar-2009

    $buayisim4 reproduces Mar-2009

    $buayisim5 reproduces Jan-2009

    $buayisim6 reproduces Dec-2008

     

    Whatever i do i don't get the february. 4 should produce february but instead of that i get march like the 3.

    Does anyone have an idea ??

     

    thanks...

     

     

×
×
  • 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.