I have this simple table:
col1 | col2
-----------
1234 | ABX_123
2134 | ADG_464
6546 | SFF_356
1495 | ABN_954
9465 | FHS_356
...
etc.
col1 is of type int(10), col2 is varchat(25).
So what I want is when I have something like "ABX_123" or "ADG_646" (value from col2) to output corresponding value from col1. This is what I tried:
// somewhere in script i get $data array which contains some of the values that are in col2.
// make a connection
$mysqli = new mysqli("localhost", "www", "", $dbname);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
// prepare a query
if ($stmt = $mysqli->prepare("select * from sometable where col2 = ?")) {
while (list($val1, $val2) = each($data)) {
$stmt->bind_param("s", $val2); // i know $val2 will be something like "ABX_123"
$stmt->execute();
$stmt->bind_result($t1, $t2);
while($stmt->fetch()) {
echo " (" . $t1 . ", " . $t2 . ") <br>";
}
}
$stmt->close();
}
$mysqli->close();
I used this "prepare" function because i have a lots of stuff in $data that need to be checked (like 30 000).
Anyway this is what I get for result in web browser:
(1115188259[COLOR=Red]44531[/COLOR] , ABX_123)
(2134 , ADG_464)
(1115188259[COLOR=Red]49843[/COLOR] , SFF_356)
(1495 , ABN_954)
(1115188259[COLOR=Red]52762[/COLOR] , FHS_356)
...
etc.
So every second line turns out to have wrong number. 😕 I marked numbers that are different in red.
Note:
111518825944531 = 1234 + 111518825943297
111518825949843 = 6546 + 111518825943297
111518825952762 = 9654 + 111518825943297
.
So I instead of 1234 get some big number which is 1234 + 111518825943297 . And this big additional number (111518825943297) turns out to be different time from time to time. I use sessions also in script, but dont know if that really matters.
Can anyone pls help ? Thx