开发者

Adding extra data to a Variable

Right now, my code plucks out only one value using Mysql. So I thought I might aswell add each found result to a variable, however I dont know how to do this.

This must be a very basic question, but I cant find a answer for it

    echo '<table border="1">';
  echo "<tr><td><b>Surname</b></td><td><b>Title/Name</b></td><td><b>Numbers</b></td><td><b>Telephone</b></td><td><b>Edit</b></td><td><b>Del</b></td></tr>\n";
  while ($row= mysql_fetch_array($result)) {
  $Surname = $row["Surname"];
  $Title = $row["TitleName"];
  $Email = $row["Email"];
  $Telephone = $row["Telephone"];
  $id = $row["id"];
  $MooringNumbers = $row['Number'];  
  $Assignedto['AssignedTo'];  
  }
  $MooringQuery = "select * FROM mooring WHERE AssignedTo='$id'";
  $MooringResult = mysql_query($MooringQuery) or die("Couldn't execute query");
  while ($row1= mysql_fetch_array($MooringResult)) {
  $AssignedTo = $row1["AssignedTo"];
  $MooringNumbers = $row1["Number"];
    echo '<tr><td>' .$Surname.'</td><td>'.$Title.'</td><td>'.$MooringNumbers . '</td><td>'.$Telephone.'</td><td>' . '<a href="rlayCustomerUpdtForm.php?id='.$id.'">[EDIT]</a></td>'.'<td>'. '<a href="deleteCustomer.php?id='.$id.'">[x]</a></td>'. '</tr&开发者_运维技巧gt;';   
}


$rows = array();
while($row = mysql_fetch_array($dbResult)) {
    $rows[] = $row;
}

You can iterate over $rows using foreach:

foreach($rows as $row) {
    // do something with $row
}

In case you use PDO for your database access you could also use the fetchAll() method on the result object which returns an array similar to $rows in the above code.


Perhaps I misunderstand the question, but the answer sounds as simple as putting the last few lines into the outer while loop:

while ($row= mysql_fetch_array($result)) {
  $Surname = $row["Surname"];
  $Title = $row["TitleName"];
  $Email = $row["Email"];
  $Telephone = $row["Telephone"];
  $id = $row["id"];
  $MooringNumbers = $row['Number'];  
  $Assignedto['AssignedTo'];  
  $MooringQuery = "select * FROM mooring WHERE AssignedTo='$id'";
  $MooringResult = mysql_query($MooringQuery) or die("Couldn't execute query");
  while ($row1= mysql_fetch_array($MooringResult)) {
    $AssignedTo = $row1["AssignedTo"];
    $MooringNumbers = $row1["Number"];
    echo '<tr><td>' .$Surname.'</td><td>'.$Title.'</td><td>'.$MooringNumbers . '</td><td>'.$Telephone.'</td><td>' . '<a href="rlayCustomerUpdtForm.php?id='.$id.'">[EDIT]</a></td>'.'<td>'. '<a href="deleteCustomer.php?id='.$id.'">[x]</a></td>'. '</tr>';   
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜