Found info on select multiple, but then what? I know it's an array but what step do I follow to get my output. Using IPlanet and MySQL.
here is the code.
<form method=\"post\" action=\"pdtest.php\">
<table border=0 cellpadding=5 cellspacing=5>
<tr>
<td rowspan=2><select name=\"sel_server[]\" size=30 multiple>
";
while ($row = mysql_fetch_array($sql_result)) {
$hostname = $row["hostname"];
echo "
<option value=\"$hostname\">$hostname</option>
";
}
echo "
</select></td>
code for the other page:
<?php
// file name: powerdown1.php
//create connection
$connection = mysql_connect("localhost", "root") or die ("couldn't connect to server.");
// select database
$db = mysql_select_db("toolboxdb",$connection) or die ("couldn't connect to database.");
// create sql statement
$sql = "select * from powerdown where hostname = \"$sel_server\"";
// execute SQL query and get result
$sql_result = mysql_query($sql,$connection) or die ("couldn't execute query.");
if (!$sql_result) {
echo "<P>Couldn't get list!";
} else {
echo "
<html>
looked at this for a week and not able to grasp the array part.
Thanks for the help!
select multiple and array's = no hair left
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
To get your output you would need to know what the array looks like so put this code into pdtest.php:
You'll see that each selected value is an array element within $_POST['sel_server']. To work with this information you could use foreach():
Obviously you could do stuff other than echo within the foreach loop. It may be an idea to read up on array handling functions within PHP to find the best solution for what you want to do with the information.
Mac
Code: Select all
echo '<pre>';
print_r($_POST);
echo '</pre>';Code: Select all
foreach ($_POSTї'sel_server'] as $value) {
echo $value.' was selected<br />';
}Mac
This helps -- But?
This helps alot.. Thanks
but how can I use this info.
I need to display a list of servers and there data. Do I do this at the $sql or after?
Thanks for your patience.[quote][/quote]
but how can I use this info.
I need to display a list of servers and there data. Do I do this at the $sql or after?
Thanks for your patience.[quote][/quote]
code would help
See the code might help!
// file name: pdtest.php
//create connection
$connection = mysql_connect("localhost", "root") or die ("couldn't connect to server.");
// select database
$db = mysql_select_db("toolboxdb",$connection) or die ("couldn't connect to database.");
// create sql statement
$sql = "select * from powerdown";
// execute SQL query and get result
$sql_result = mysql_query($sql,$connection) or die ("couldn't execute query.");
if (!$sql_result) {
echo "<P>Couldn't get list!";
} else {
echo "
<html>
<head>
<title>Server Report</title>
</head>
<body bgcolor=\"#999999\">
<h1>Power Down Server Report</h1>
<table border=1 cellpadding=5 cellspacing=5>
<tr><th>Hostname</th><th>Point of Contact</th><th>Ext</th><th>Applications on the Server</th><th>Server Specific Notes</th></tr>
";
// fetch row and assign a name to the variable
while ($row = mysql_fetch_array($sql_result)) {
$hostname = $row["hostname"];
$point_contact = $row["point_contact"];
$contact_number = $row["contact_number"];
$server_application = $row["server_application"];
$pd_notes = $row["pd_notes"];
foreach ($_POST['sel_server'] as $value) {
echo "<tr><td><h1>$value</h1></td><td><h1>$point_contact</h1></td><td><h1>$contact_number</h1></td><td><h1>$server_application</h1></td><td><h1>$pd_notes</h1></td></tr>";
}
}
}
echo "
</table>
</body>
</html>
";
// file name: pdtest.php
//create connection
$connection = mysql_connect("localhost", "root") or die ("couldn't connect to server.");
// select database
$db = mysql_select_db("toolboxdb",$connection) or die ("couldn't connect to database.");
// create sql statement
$sql = "select * from powerdown";
// execute SQL query and get result
$sql_result = mysql_query($sql,$connection) or die ("couldn't execute query.");
if (!$sql_result) {
echo "<P>Couldn't get list!";
} else {
echo "
<html>
<head>
<title>Server Report</title>
</head>
<body bgcolor=\"#999999\">
<h1>Power Down Server Report</h1>
<table border=1 cellpadding=5 cellspacing=5>
<tr><th>Hostname</th><th>Point of Contact</th><th>Ext</th><th>Applications on the Server</th><th>Server Specific Notes</th></tr>
";
// fetch row and assign a name to the variable
while ($row = mysql_fetch_array($sql_result)) {
$hostname = $row["hostname"];
$point_contact = $row["point_contact"];
$contact_number = $row["contact_number"];
$server_application = $row["server_application"];
$pd_notes = $row["pd_notes"];
foreach ($_POST['sel_server'] as $value) {
echo "<tr><td><h1>$value</h1></td><td><h1>$point_contact</h1></td><td><h1>$contact_number</h1></td><td><h1>$server_application</h1></td><td><h1>$pd_notes</h1></td></tr>";
}
}
}
echo "
</table>
</body>
</html>
";