dear all, I have made a look-up talbe in php that reads from a sql table.

one table, pair has pair_id as the primary key

one table, pairHistory has actions when information for a pair_id changes

and the look-up table logs the transactions, the many to one relationship pair id, a classic many to one relationship.

What I need: a php or sql function that iterates throu the sql table each time I call it or a way to do that.

Lookup table pairHistoryLookup:
how can I get each row for pairId 15, one by one?

Please help!

You did not specify which database you are working with. This is important, but I will assume mysql.

Here is a code example that will show you how to connect to mysql, how to select a specific database, execute a query, then work with the returned recordset.


$server = "localhost"; // Name or IP of database server.
$user   = ""; // username
$pwd    = ""; // password
$db     = ""; // Name of database to connect to.

if (!$cnn = mysql_connect($server,$user,$pwd )) {
  die("mysql_connect() failed");

if (!mysql_select_db($db,$cnn)) {
  die("Could not select database named ".$db);

$sql = "select * from pairHistoryLookup where pairID = 15";

/* Execute the query. */
if (!$res = @mysql_query($sql)) {
  return false;
/* Create an array of arrays out of the recordset. */
while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
  $data[] = $row;

/* Now iterate through the recordset creating a simple table. */
echo "<style>table.dump { font-family:Arial; font-size:8pt; }</style>";
echo "<table class=\"dump\" border=\"1\" cellpadding=\"1\" cellspacing=\"0\">\n";
echo "<tr>";
echo "<th>#</th>";
foreach($data[0] as $key=>$val) {
  echo "<th><b>";
  echo $key;
  echo "</b></th>";
echo "</tr>\n";
$row_cnt = 0;
foreach($data as $row) {
  echo "<tr align='center'>";
  echo "<td>".$row_cnt."</td>";
  foreach($row as $val) {
    echo "<td>";
    echo $val;
    echo "</td>";
echo "</table>\n";    

This article has been dead for over six months. Start a new discussion instead.