klepec Posted March 27, 2012 Share Posted March 27, 2012 Hello, This is my mysql search: $req="%".mysql_real_escap.......; "SELECT companyID, cName FROM bcompany WHERE companyID LIKE '$req' OR cName LIKE '$req' ORDER BY companyID LIMIT 10" For example my search ($req) is krneki. There is one record in database which matches the criteria. And the array is like: array 0 => string '7' (length=1) 'companyID' => string '7' (length=1) 1 => string 'krneki jao' (length=10) 'cName' => string 'krneki jao' (length=10) Is it ok that there are double values in array i fetch from mysql? Quote Link to comment https://forums.phpfreaks.com/topic/259796-doubled-array/ Share on other sites More sharing options...
seanlim Posted March 27, 2012 Share Posted March 27, 2012 Yes, that is entire normal and to be expected, if you have used the mysql_fetch_array function. The documentation states that it will "fetch a result row as an associative array, a numeric array, or both". When the optional second parameter is left out, it defaults to retrieving both. If you just want a numerial array, you can use mysql_fetch_row, or if you want a associative array, you can use mysql_fetch_assoc. Quote Link to comment https://forums.phpfreaks.com/topic/259796-doubled-array/#findComment-1331517 Share on other sites More sharing options...
cpd Posted March 27, 2012 Share Posted March 27, 2012 Or you can just specify what you want in the mysql_fetch_array function. $result = mysql_fetch_array($stmt, MYSQL_BOTH); // Default $result = mysql_fetch_array($stmt, MYSQL_ASSOC); $result = mysql_fetch_array($stmt, MYSQL_NUM); Quote Link to comment https://forums.phpfreaks.com/topic/259796-doubled-array/#findComment-1331520 Share on other sites More sharing options...
klepec Posted March 27, 2012 Author Share Posted March 27, 2012 Ahaa, I understand now. It is because of two different options. $row["column_name"] or $row[number]. Thanks for the explanation Quote Link to comment https://forums.phpfreaks.com/topic/259796-doubled-array/#findComment-1331534 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.