G-Force
asked on
Retrieving values from 2 db tables and selecting the checkboxes.
Hi,
I currently have a problem and I've been working on it the whole day but I'm still getting no where.
The situation is...
I have 2 db tables: Tyres and Customers
Tyres
-------------------------- -
| Brand | tyreId |
-------------------------- -
| Yokohama | 10 |
| GoodYear | 11 |
| Michelin | 12 |
Customers
-------------------------- -
| Name | custId | tyreId |
-------------------------- -
| John | J1 | 10 |
| John | J1 | 11 |
| Tom | T2 | 10 |
I'm displaying the Tyres table using checkboxes on a page.
Then, for a customer, say John, he can have more than 1 tyre order.
How do I select 2 checkboxes out of the 3?
I've tried using nested while loop but it seems that it only loop through once and selects one checkbox and that's it.
This was what I did:
<?
$query2 = "SELECT * FROM Customer where custID='J1'";
$result2 = mysql_query($query2) or die( mysql_error() );
while ($r = mysql_fetch_array($result2 )){
$tyreID[ ] = $r["tyreID"];
}
echo "<tr>";
echo "<td>";
echo "Tyres:";
echo "</td>";
echo "<td>";
$query = "SELECT * FROM Tyres";
$result = mysql_query($query) or die( mysql_error() );
while ($r = mysql_fetch_array($result) ){
$Brand = $r["Brand"];
$tyreId = $r["tyreId"];
if (is_array($tyreID)){
while(list($key, $ID) = each($tyreID)){
echo "<tr>";
echo "<td>";
echo "</td>";
echo "<td>";
if ($tyreId == $ID){
echo "<input type=checkbox name='custOrder' Value=$typeId selected> $Brand";
}
else{
echo "<input type=checkbox name='custOrder' Value=$typeId> $Brand";
}
echo "</td>";
echo "</tr>";
}
}
}
echo "</td>";
echo "</tr>";
?>
I'm not sure if this logic is the right one to use.
If you have better suggestions, feel free to comment.
I need help as soon as possible. Thanks!
I currently have a problem and I've been working on it the whole day but I'm still getting no where.
The situation is...
I have 2 db tables: Tyres and Customers
Tyres
--------------------------
| Brand | tyreId |
--------------------------
| Yokohama | 10 |
| GoodYear | 11 |
| Michelin | 12 |
Customers
--------------------------
| Name | custId | tyreId |
--------------------------
| John | J1 | 10 |
| John | J1 | 11 |
| Tom | T2 | 10 |
I'm displaying the Tyres table using checkboxes on a page.
Then, for a customer, say John, he can have more than 1 tyre order.
How do I select 2 checkboxes out of the 3?
I've tried using nested while loop but it seems that it only loop through once and selects one checkbox and that's it.
This was what I did:
<?
$query2 = "SELECT * FROM Customer where custID='J1'";
$result2 = mysql_query($query2) or die( mysql_error() );
while ($r = mysql_fetch_array($result2
$tyreID[ ] = $r["tyreID"];
}
echo "<tr>";
echo "<td>";
echo "Tyres:";
echo "</td>";
echo "<td>";
$query = "SELECT * FROM Tyres";
$result = mysql_query($query) or die( mysql_error() );
while ($r = mysql_fetch_array($result)
$Brand = $r["Brand"];
$tyreId = $r["tyreId"];
if (is_array($tyreID)){
while(list($key, $ID) = each($tyreID)){
echo "<tr>";
echo "<td>";
echo "</td>";
echo "<td>";
if ($tyreId == $ID){
echo "<input type=checkbox name='custOrder' Value=$typeId selected> $Brand";
}
else{
echo "<input type=checkbox name='custOrder' Value=$typeId> $Brand";
}
echo "</td>";
echo "</tr>";
}
}
}
echo "</td>";
echo "</tr>";
?>
I'm not sure if this logic is the right one to use.
If you have better suggestions, feel free to comment.
I need help as soon as possible. Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oh, thanks to you both, but I've found a way to solve this problem here.
jausions, I'll give you the 30 points 'cause I see that you do put in effort.
Anyway, thanks!
jausions, I'll give you the 30 points 'cause I see that you do put in effort.
Anyway, thanks!
/* code */
foreach($tireID as $ID){
/* end code */
just this one line, nothing else