Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi all. I have limited experience with PHP/MYsql websites, but I have run into a problem.
I have two tables I need to dispolay in a certain way on a website.
First table:
device-
dev_id
name
type_id
etc...
Second table:
Type-
type_id
type
Now, i need to display the type associated with the device in a dropdown box.
example: PC101 --> type Computer
Router1 --> type router
I use this query:
*****************************************************************************Code: Select all
<?
// ********************************************************************************
$sql1 = "SELECT * FROM type";
$result1 = @mysql_query($sql1,$connection) or die(mysql_error());
$num1 = @mysql_num_rows($result1);
if ($num1 < 1) {
//if there are no results, display message
$display_block = "<p><em>Sorry, No Results.</em></p>";
} else {
//if results are found, loop through them
//and make a form selection block
while ($row1 = mysql_fetch_array($result1)) {
$id1 = $row1['type_id'];
$name1 = $row1['type'];
$option_block1 .= "<option value=\"$id1\">$name1</option>";
}
//create the entire form block
$echo_type = "
<p><strong>Type:</strong><br>
<select name=\"type_id\">
$option_block1
</select>
</p>
";
}
// *******************************************************************************
?>Now this will display all the types of devices in an option dropdown menu, but I want to display the current type assigned to a particular device in the first option row, then display all possible device types under that. What I am trying to do is make an computer inventory website. when I select a Computer or switch i want the page to display all the information about that device, then offer me options incase i want to change the device type.
When I run this query: I get only one result
Code: Select all
<?
// ********************************************************************************
$sql1 = "select * from type, device where type.type_id = device.type_id AND dev_id = '$_POST[id]';
";
$result1 = @mysql_query($sql1,$connection) or die(mysql_error());
$num1 = @mysql_num_rows($result1);
if ($num1 < 1) {
//if there are no results, display message
$display_block = "<p><em>Sorry, No Results.</em></p>";
} else {
//if results are found, loop through them
//and make a form selection block
while ($row1 = mysql_fetch_array($result1)) {
$id1 = $row1['type_id'];
$name1 = $row1['type'];
$option_block1 .= "<option value=\"$id1\">$name1</option>";
}
//create the entire form block
$echo_type = "
<p><strong>Type:</strong><br>
<select name=\"type_id\">
$option_block1
</select>
</p>
";
}
// *******************************************************************************
?>Any help would be greatly appreciated.
Thanks
Pimptastic | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]