Reputation: 7
I'm totally stuck! I need to create navigation buttons in order to go through records that match a specific Id. So far I have only been able to retrieve 1 record (the first one). I am using the following code to do so:
$query = "SELECT t1.requester_name, t1.requester_email, t1.client_name, t1.client_country, t1.machine_quantity, t1.severity, t1.sales_connect, t1.request_status, t2.serial_type, t2.serial_model, t2.serial_number, t2.machine_status, t2.machine_config, t2.brand, t2.tier, t2.request_id
FROM requests t1
LEFT JOIN serialnumbers t2
ON t1.request_id = t2.request_id
WHERE t1.request_id = {$id} ";
$results = mysql_query($query, $connection);
$row = mysql_fetch_assoc($results);
The records are coming from 2 distinct tables and while I am having no trouble with the Request Table (Always one row), I cannot manage to figure out how to get every row in the Serial Numbers table (one to many relationship).
I am using a html form to display these values... Here is a sample of how I am doing so:
<input type="text" value="<?php echo $row['serial_type']; ?>" id="machineType" name="machineType[]" />
Any ideas on how I can achieve this objective?
Upvotes: 0
Views: 202
Reputation: 452
you are going to want to make your $row = mysql_fetch_assoc a while loop.
while ($row = mysql_fetch_assoc($results)){
echo '<input type="text" value="'.$row['serial-type']." id="machineType" name="machineType[]" />';
}
something along those lines.
Upvotes: 1