lhaluska
asked on
Php List box populated from MSsql query
I am trying to create a list box from a php query but I am getting an error what am I doing wrong?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Lab Support Service Request Page</title>
</head>
<body>
<?php
$dbc = mssql_connect ('cacapppro01.cup.com','ns kinfo','we bres');
$query = mssql_query("
SELECT *
FROM dbo.NSKSystemInfo
WHERE (SystemState_ID = 1)
ORDER BY systemName");
?>
<?
echo "<select size="10" multiple="yes" value="System_ID" display="SystemName" name=\"SYSTEM_ID\"></selec t>";
mssql_close($dbc);
?>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Lab Support Service Request Page</title>
</head>
<body>
<?php
$dbc = mssql_connect ('cacapppro01.cup.com','ns
$query = mssql_query("
SELECT *
FROM dbo.NSKSystemInfo
WHERE (SystemState_ID = 1)
ORDER BY systemName");
?>
<?
echo "<select size="10" multiple="yes" value="System_ID" display="SystemName" name=\"SYSTEM_ID\"></selec
mssql_close($dbc);
?>
</body>
</html>
i think you are trying to populate select box with the DB values?
ASKER
Yes, The table I want to show in the list is "SystemName" and the value I want is "System_ID".
just an idea
<?php
include "canada_hotels/library/con nection.ph p";
$query = "SELECT * FROM tblcategory";
$result = mysql_query($query);
?>
<select name='category'>
<option></option>
<?
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<option value='{$row['categoryID'] }'";
echo ">{$row['categoryname']}</ option>";
}
?>
</select>
<?php
include "canada_hotels/library/con
$query = "SELECT * FROM tblcategory";
$result = mysql_query($query);
?>
<select name='category'>
<option></option>
<?
while($row = mysql_fetch_array($result,
{
echo "<option value='{$row['categoryID']
echo ">{$row['categoryname']}</
}
?>
</select>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
So I have a couple of questions. Why is it that I need a "mssql_select_db" if I have the "$query" and the "$dbc" variable? The code is now working with your help from the example, But why am I getting a white space at the top of my list box?
<?php
$dbc = mssql_connect ('cacapppro01.cup.com','ns kinfo','we bres');
$query = mssql_query("
SELECT *
FROM dbo.NSKSystemInfo
WHERE (SystemState_ID = 1)
ORDER BY systemName");
?>
<select size="10" multiple="yes" value="System_ID" display="SystemName" name="SYSTEM">
<option></option>
<?
while($row = mssql_fetch_array($query, MSSQL_ASSOC))
{
echo "<option value='{$row['System_ID']} '";
echo ">{$row['systemName']}</op tion>";
}
?>
</select>
<?
mssql_close($dbc);
?>
<?php
$dbc = mssql_connect ('cacapppro01.cup.com','ns
$query = mssql_query("
SELECT *
FROM dbo.NSKSystemInfo
WHERE (SystemState_ID = 1)
ORDER BY systemName");
?>
<select size="10" multiple="yes" value="System_ID" display="SystemName" name="SYSTEM">
<option></option>
<?
while($row = mssql_fetch_array($query, MSSQL_ASSOC))
{
echo "<option value='{$row['System_ID']}
echo ">{$row['systemName']}</op
}
?>
</select>
<?
mssql_close($dbc);
?>
ASKER
I answered my second question in the last post it was the option above the loop. Oh I have one more question how do I make it so users can not see the php code if they click view source?
people can't see php code rather they can only see client side code for example HTML, CSS, JAVASCRIPT etc and PHP is server side language
ASKER
oh ok thank you.