Link to home
Start Free TrialLog in
Avatar of lhaluska
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','nskinfo','webres');
$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\"></select>";
mssql_close($dbc);

?>
</body>
</html>
Avatar of Aamir Saeed
Aamir Saeed
Flag of Pakistan image

i think you are trying to populate select box with the DB values?
Avatar of lhaluska
lhaluska

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/connection.php";
      
      $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>
ASKER CERTIFIED SOLUTION
Avatar of Aamir Saeed
Aamir Saeed
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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','nskinfo','webres');
$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']}</option>";      
      }
?>
      </select>


<?
mssql_close($dbc);

?>
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
oh ok thank you.