Jump to content

Doubled array


klepec

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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