Jump to content

budimir

Members
  • Posts

    522
  • Joined

  • Last visited

Everything posted by budimir

  1. OK, so you could use my code I gave you, but as mac_gyver said you could end up with the same invid on more records if few users open that form at same time. If you want to continue with that concept you should check if invid you're inserting already exists in DB before storing data in DB.
  2. <label for="textfield">Repair ID Number:</label> <input name="invid" type="text" value="<?php echo '".$new_repair."'; ?>" id="invid" size="3" onKeyDown="limitText(this.form.invid,this.form.countdown,3);" onKeyUp="limitText(this.form.invid,this.form.countdown,3);"; /> But before that you need to use the select query to get the max invid you have in database. Do you know how invid is setup in you're DB? Is that autoincrement field? Who setup the database?
  3. SELECT MAX(invid) as last_inserted FROM table_name Php part $data = mysqli_fetch_row($query); $last_inserted = $data["last_inserted"]; $new_repair = $last_inserted + 1; That's a simple solution, if that is what you need.
  4. What do you get when you echo $year = $_POST['year'];? Also, can you give us error which you recive?
  5. I guess what you need is not ID of inserted row, because that is not relevant to user. I would suggest that you create a column called document number or repair number or whatever. When you create new repair you call a query on you're database, get max repair number and add one or whatever you want it to be. That way you will always have automatic repair number. ID in database you should set to autoincrement and add primary key to it. Is that what you need?
  6. Guys, thanks for all you're help. I found a problem and it was on another script that was inserting data into that table. Something happened during the scheduled start and it didn't finish inserting all the records. Found the problem, fixed it and now I can get all the records I need. Once again, thanks for you're help.
  7. Hi, I need some help with the query to find duplicate rows on specific value. I have tried many queries, but I can't find it. For now I have this. My sql structure: id INT(11) NOT NULL AUTO_INCREMENT, vrijeme TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, pocetni_broj VARCHAR(55) DEFAULT NULL, zamjenski_broj VARCHAR(55) DEFAULT NULL, glavni_broj VARCHAR(55) DEFAULT NULL, postoji_zamjena INT(1) DEFAULT NULL, PRIMARY KEY (id) And my query is: SELECT * FROM zamjene_brojeva GROUP BY glavni_broj HAVING COUNT(glavni_broj) > 1 Thta is giving me all duplicate values in table. But how do I find duplicate values where column glavni_broj has value 966 45 19-68? I know that there is 4 rows with that value in glavni_broj. I have tried to put Where in that, but than query fails. Any ideas how to do it?
  8. I think I finally got it working. One of the problems I found a case where function couldn't return any data. Second thing is that the global connection wasn't setup properly for some reason. I don't understand why no error messages came up. Anyways, now it's working. Thank you for all you're help!
  9. OK, so I'm sure problem is with mysqli. When I use same function with mysql it works. Why is it that mysqli_query is not trigering inside that function??? That's a complete mistery for me. It's not even reporting any error messages.
  10. No error message. This is what I use: error_reporting(E_ALL); ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1);
  11. No errors! I have error_reporting(E_ALL) and nothing is reported. That's why I don't know what is wrong. Select query is OK, but mysqli_query is not retrieveing any information
  12. I'm rewriting my aplication to work with mysqli and one function that I have created is not working anymore. I don't know why connection to db is not working anymore. It worked on mysql. Can you see what is the problem? function zamjena_broja($kataloski_broj){ global $conn_mysqli; $kataloski_broj_data = array(); //Traženje zamjenskog broja $upit_zamjena = "SELECT pocetni_broj, zamjenski_broj, glavni_broj FROM zamjene_brojeva WHERE glavni_broj = '$kataloski_broj' OR pocetni_broj = '$kataloski_broj'"; $rezultat_zamjena = mysqli_query($conn_mysqli, $upit_zamjena) or die (mysqli_error($conn_mysqli)); while($row = mysqli_fetch_array($rezultat_zamjena)){ $kataloski_broj_data[] = $row["zamjenski_broj"]; $kataloski_broj_data[] = $row["pocetni_broj"]; } $kataloski_broj = array_map("unserialize", array_unique(array_map("serialize", $kataloski_broj_data))); //var_dump($kataloski_broj); return $kataloski_broj; } My connection: <?php //Veza na bazu - mysqli protokol $DBServer = 'localhost'; // e.g 'localhost' or '192.168.1.100' $DBUser = 'xxxx'; $DBPass = 'xxxx'; $DBName = 'xxxdb'; $conn_mysqli = new mysqli($DBServer, $DBUser, $DBPass, $DBName); global $conn_mysqli; // check connection if ($conn_mysqli->connect_error) { trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR); } ?>
  13. Please post you're code so we could help you.
  14. Ok, I found a soltuion to my problem. $upit = "SELECT Br_artikla, Prodana_kolicina, Godina FROM katalog_pribora_povijest WHERE Br_artikla IN ('".implode("','", $kataloski)."') GROUP BY Godina";
  15. You're insert statment would be: $sql = "INESRT INTO table (table_fileds) VALUES ($values_to_store)"; $query = mysqli_query($conn,$sql); As I can see you are stating to work with mysql and php, so I would advise you to seach through google a bit and than ask for some help. Nobody is going to give you a complete solution. A push in right direction you will get here.
  16. Guys, What is wrong in this query? It's throwing an error. $upit = "SELECT Br_artikla, Prodana_kolicina, Godina FROM katalog_pribora_povijest WHERE Br_artikla = " . implode(' OR Br_artikla = ', $kataloski) . " GROUP BY Godina"; Error I get: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '02 83-01 OR Br_artikla = 503 86 27-02 OR Br_artikla = 503 86 27-03 OR Br_artikla' at line 3
  17. Thanks Barand! You have pointed me to the right direction. I have solved my problem. Thank you very much. This is the function and whole script how I tested it if anyone needs it. <?php include ("../../admin/servis/include/session.php"); //funkcija za traženje zamjene brojeva function zamjena_broja($kataloski_broj){ $kataloski_broj_data = array(); //Traženje zamjenskog broja $upit_zamjena = "SELECT pocetni_broj, zamjenski_broj, glavni_broj FROM zamjene_brojeva WHERE glavni_broj = '$kataloski_broj' OR pocetni_broj = '$kataloski_broj'"; $rezultat_zamjena = mysql_query($upit_zamjena) or die (mysql_error()); while($row = mysql_fetch_array($rezultat_zamjena)){ $kataloski_broj_data[] = $row["zamjenski_broj"]; $kataloski_broj_data[] = $row["pocetni_broj"]; } $kataloski_broj = array_map("unserialize", array_unique(array_map("serialize", $kataloski_broj_data))); var_dump($kataloski_broj); return $kataloski_broj; } ?> <form method="GET" action="<?php $_SERVER["PHP_SELF"]; ?>"> <input type="text" name="kataloski" value="" /> <input type="submit" name="submit" value="Trazi" /> </form> <?php $kataloski = zamjena_broja($_GET["kataloski"]); foreach ($kataloski as $value) { echo "$value<br>"; } /* echo $kataloski[0]; echo "<br>"; echo $kataloski[1]; echo "<br>"; echo $kataloski[3]; echo "<br>"; echo $kataloski[5]; */ ?>
  18. Barand, I have almost made it. I have this code: //funkcija za traženje zamjene brojeva function zamjena_broja($kataloski_broj){ $kataloski_broj_data = array(); //Traženje zamjenskog broja $upit_zamjena = "SELECT pocetni_broj, zamjenski_broj, glavni_broj FROM zamjene_brojeva WHERE glavni_broj = '$kataloski_broj' OR pocetni_broj = '$kataloski_broj'"; $rezultat_zamjena = mysql_query($upit_zamjena) or die (mysql_error()); while($row = mysql_fetch_array($rezultat_zamjena)){ $kataloski_broj_data[] = $row["zamjenski_broj"]; $kataloski_broj_data[] = $row["pocetni_broj"]; } $kataloski_broj = $input = array_map("unserialize", array_unique(array_map("serialize", $kataloski_broj_data))); var_dump($kataloski_broj); //Ovo je ispis koji baca funkcija return $kataloski_broj; } On var_dump($kataloski_broj) I get this value: array (size=4) 0 => string '544 02 83-01' (length=12) 1 => string '503 86 27-02' (length=12) 3 => string '503 86 27-03' (length=12) 5 => string '503 86 28-03' (length=12) Which is totally OK. Now my problem is that on return I get array. This is how I test my function: <form method="GET" action="<?php $_SERVER["PHP_SELF"]; ?>"> <input type="text" name="kataloski" value="" /> <input type="submit" name="submit" value="Trazi" /> </form> <?php $kataloski = zamjena_broja($_GET["kataloski"]); echo "<br>Kataloški koji tražimo - $kataloski<br> Pronađeni kataloški:<br> "; //Pregled array ?> What am I doing wrong that function is not returning values, but Array???
  19. I have tried it and returns nothing array is empty. This is how I reworked the function. function zamjena_broja($kataloski_broj){ $kataloski_broj_data = array(); //Traženje zamjenskog broja $upit_zamjena = "SELECT pocetni_broj, zamjenski_broj, glavni_broj FROM zamjene_brojeva WHERE glavni_broj = '$kataloski_broj' OR pocetni_broj = '$kataloski_broj'"; $rezultat_zamjena = mysql_query($upit_zamjena) or die (mysql_error()); while($row = mysql_fetch_array($rezultat_zamjena)){ $kataloski_broj_data['G'][] = $row["zamjenski_broj"]; $kataloski_broj_data['Z'][] = $row["pocetni_broj"]; /* echo "Glavni broj A - $kataloski_broj_g<br> Početni broj A - $kataloski_broj_p<br> Broj zamjena A - $broj_zamjena<br>"; */ //Ovdje su svi zamjenski brojevi //print_r($kataloski_broj_p); } //Ovdje je u uvijek jedan glavni broj //print_r($kataloski_broj_g); //Ovo je ispis koji baca funkcija return $kataloski_broj_data; }
  20. Barand, This is the final result I need. I managed to link them in an array. function zamjena_broja($kataloski_broj){ $kataloski_broj_g = array(); $kataloski_broj_p = array(); //Traženje zamjenskog broja $upit_zamjena = "SELECT pocetni_broj, zamjenski_broj, glavni_broj FROM zamjene_brojeva WHERE glavni_broj = '$kataloski_broj' OR pocetni_broj = '$kataloski_broj'"; $rezultat_zamjena = mysql_query($upit_zamjena) or die (mysql_error()); while($row = mysql_fetch_array($rezultat_zamjena)){ $kataloski_broj_g['G'] = $row["zamjenski_broj"]; $kataloski_broj_p['Z'] = $row["pocetni_broj"]; $broj_zamjena = mysql_num_rows($rezultat_zamjena); /* echo "Glavni broj A - $kataloski_broj_g<br> Početni broj A - $kataloski_broj_p<br> Broj zamjena A - $broj_zamjena<br>"; */ //Ovdje su svi zamjenski brojevi print_r($kataloski_broj_p); } //Ovdje je u uvijek jedan glavni broj print_r($kataloski_broj_g); //Ovo je ispis koji baca funkcija return $kataloski_broj_p; return $kataloski_broj_g; } Can you tell me how to have sam result from: print_r($kataloski_broj_p); print_r($kataloski_broj_g); in return $kataloski_broj_p; return $kataloski_broj_g; That is only problem I'm facing now.
  21. Barand, I have made it to get the result I need and now the function looks like this. //Traženje zamjenskog broja $upit_zamjena = "SELECT pocetni_broj, zamjenski_broj, glavni_broj FROM zamjene_brojeva WHERE glavni_broj = '$kataloski_broj' OR pocetni_broj = '$kataloski_broj'"; $rezultat_zamjena = mysql_query($upit_zamjena) or die (mysql_error()); while($row = mysql_fetch_array($rezultat_zamjena)){ $kataloski_broj_g = $row["zamjenski_broj"]; $kataloski_broj_p = $row["pocetni_broj"]; $broj_zamjena = mysql_num_rows($rezultat_zamjena); echo "Glavni broj A - $kataloski_broj_g<br> Početni broj A - $kataloski_broj_p<br> Broj zamjena A - $broj_zamjena<br>"; } //Traženje zamjene if ($broj_zamjena == 1) { $upit_zamjena = "SELECT pocetni_broj, zamjenski_broj, glavni_broj FROM zamjene_brojeva WHERE glavni_broj = '$kataloski_broj_g'"; $rezultat_zamjena = mysql_query($upit_zamjena) or die (mysql_error()); while($row3 = mysql_fetch_array($rezultat_zamjena)) { $kataloski_broj_g2 = $row3["zamjenski_broj"]; $kataloski_broj_p2 = $row3["pocetni_broj"]; $broj_zamjena3 = mysql_num_rows($rezultat_zamjena); echo "Glavni broj C - $kataloski_broj_g2<br> Početni broj C - $kataloski_broj_p2<br> Broj zamjena C - $broj_zamjena<br>"; } } return $kataloski_broj; } Only problem now is how to output those linked numbers and main number in return $kataloski_broj. Can you help me with that?
  22. Can you show us you're code? It's hard to tell this way.
  23. Hey Barand, Let me explain the situation I need to solve. I have one article which is comeing under different part numbers (same product with different article numbers). I need to somehow get all linked numbers and use last glavni_broj to be able to identify the stock. So in the previous example that would be: Linked numbers: 503 86 27-02, 544 02 83-01, 503 86 27-03, 503 86 28-03 Main number: 544 02 83-01 Then I could use all these linked numbers to sum the stock and show to the user and also redirect him to newest number for order. That's where I can't find a solution. How to display all linked numbers.
×
×
  • 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.