Note that there are some explanatory texts on larger screens.

plurals
  1. POComparing two mysql recordsets using php
    primarykey
    data
    text
    <p>I need to compare two mysql recordsets using php</p> <p>Comparing a record in the first recordset is present in the second and returns a true value, or a false if its not present.</p> <p>The problem is once a do a single pass of the recordset it doesn't return to the beginning so i can compare the the remaining records of recordset1 to it.</p> <p>The code i'm using is:</p> <pre><code>*mysql_select_db($database_db, $db); $query_rec_teams = "SELECT tbl_items.* FROM tbl_items;"; $rec_items = mysql_query($query_rec_items, $db) or die(mysql_error()); $row_rec_items = mysql_fetch_assoc($rec_items); $totalRows_rec_items = mysql_num_rows($rec_items); $query_rec_itemsLeft = "(SELECT tbl_itemsleft.* FROM tbl_itemsLeft"; $rec_itemsLeft = mysql_query($query_rec_itemsLeft, $db) or die(mysql_error()); $row_rec_itemsLeft = mysql_fetch_assoc($rec_itemsLeft); $totalRows_rec_itemsLeft = mysql_num_rows($rec_itemsLeft); //iterate first recordset, populate variables do{ $itemPresent=0; $item=$row_rec_item['ItemID']; //iterate second recordset and compare item variable with itemID fields in recordset, if exist echo true, else echo false do { if ($row_rec_itemsLeft(['ItemID'] == $item){ itemPresent=1; } else{ itemPresent=0; } echo itemPresent; } while ($row_rec_itemsLeft = mysql_fetch_assoc($rec_itemsLeft)); } while ($row_rec_items = mysql_fetch_assoc($rec_items)); mysql_free_result($rec_itemsLeft); mysql_free_result($rec_items); ?&gt;* </code></pre> <p>would it be easier to populate the recordsets into arrays and compare the arrays instead</p> <p>help appreciated</p>
    singulars
    1. This table or related slice is empty.
    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