Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy two different mysql function returns different rows when executed upon the data retrived from single mysql_query()?
    primarykey
    data
    text
    <p>I tried this as a test purpose. And I don't know why is this happening. That's I need help from the experts. Thanks.</p> <p>Lets assume that we have a database and we have established connection with the database. Let's assume there is a table named <code>table</code>. Inside the table there are two columns- id and name. there are 5 rows of data in the table. Table structure is</p> <pre><code>| id | name | --------------- | 1 | name1 | | 2 | name2 | | 3 | name3 | | 4 | name4 | | 5 | name5 | </code></pre> <p>Now my code goes here-</p> <pre><code> &lt;?php mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); $result = mysql_query("SELECT * FROM `table`"); /* let's store this value in two different variables. */ $result1 = $result; $result2 = $result; /* let's perform mysql_fetch_array() and mysql_fetch_row() functions */ $result22 = mysql_fetch_row($result); var_dump($result22); $result11 = mysql_fetch_array($result); var_dump($result11); ?&gt; </code></pre> <p>it results :</p> <pre><code>array 0 =&gt; string '1' (length=1) 1 =&gt; string 'name1' (length=5) array 0 =&gt; string '2' (length=1) 'id' =&gt; string '2' (length=1) 1 =&gt; string 'name2' (length=5) 'name' =&gt; string 'name2' (length=5) </code></pre> <p>If i alter the order of the functions it results :</p> <pre><code>array 0 =&gt; string '1' (length=1) 'id' =&gt; string '1' (length=1) 1 =&gt; string 'name1' (length=5) 'name' =&gt; string 'name1' (length=5) array 0 =&gt; string '2' (length=1) 1 =&gt; string 'name2' (length=5) </code></pre> <p>It seems that when I perform a function upon the result of mysql_query, that function simply removes the first row from the result even if it is stored in other variable before calling the function. </p> <p>If i add a condition WHERE <code>id</code> = 1 then the second function returns false, like:</p> <pre><code>array 0 =&gt; string '1' (length=1) 'id' =&gt; string '1' (length=1) 1 =&gt; string 'name1' (length=5) 'name' =&gt; string 'name1' (length=5) boolean false </code></pre> <p>Why is this happening? Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload