Code Comments
Programming Forum and web based access to our favorite programming groups.Hi,
I have problem with php and MSSQL
I have a combobox with the name of 10 company and in my database i
have 1 table different for each company.
I need that when the user choose in the combobox one of this company
appeard the table with the data.
I think that I found part of the code that I need but i have no idea
how do that now
Please help me!
<?php
session_start();
set_time_limit(0);
error_reporting(E_ALL);
//complete "stationsqlexpress" with your particular case
$SERVER = "stationsqlexpress";
$ADMIN_NAME = "sa";
//complete pass with your pass
$ADMIN_PASS = "pass";
//complete database witht the name of database you whant to
connect to
$DATABASE = "database";
$Conexion = mssql_connect($SERVER, $ADMIN_NAME, $ADMIN_PASS)
or die ("Can't connect to Microsoft SQL Server");
mssql_select_db($DATABASE, $Conexion)
or die ("Can't connect to Database");
?>
<form name="modulo">
<select name="colori" onchange="SelectPost()">
<option value=""></option>
<option value="ROSSO">ROSSO</option>
<option value="GIALLO">GIALLO</option>
<option value="VERDE">VERDE</option>
<option value="BLU">BLU</option>
</select>
</form>
<?php
$sql="SELECT * FROM anagrafe;
$oggetto = $mssql->runquery($sql);
$mssql->closeDb();
print ($oggetto);
?>
thanks Lidia
Post Follow-up to this messageOn Mar 7, 12:01 pm, lid...@gmail.com wrote:
> Hi,
>
> I have problem with php and MSSQL
>
> I have a combobox with the name of 10 company and in my database i
> have 1 table different for each company.
>
> I need that when the user choose in the combobox one of this company
> appeard the table with the data.
>
> I think that I found part of the code that I need but i have no idea
> how do that now
>
> Please help me!
>
> <?php
> session_start();
> set_time_limit(0);
> error_reporting(E_ALL);
>
> //complete "stationsqlexpress" with your particular case
> $SERVER = "stationsqlexpress";
> $ADMIN_NAME = "sa";
> //complete pass with your pass
> $ADMIN_PASS = "pass";
> //complete database witht the name of database you whant to
> connect to
> $DATABASE = "database";
>
> $Conexion = mssql_connect($SERVER, $ADMIN_NAME, $ADMIN_PASS)
> or die ("Can't connect to Microsoft SQL Server");
>
> mssql_select_db($DATABASE, $Conexion)
> or die ("Can't connect to Database");
> ?>
>
> <form name="modulo">
> <select name="colori" onchange="SelectPost()">
> <option value=""></option>
> <option value="ROSSO">ROSSO</option>
> <option value="GIALLO">GIALLO</option>
> <option value="VERDE">VERDE</option>
> <option value="BLU">BLU</option>
> </select>
> </form>
>
> <?php
> $sql="SELECT * FROM anagrafe;
> $oggetto = $mssql->runquery($sql);
> $mssql->closeDb();
> print ($oggetto);
> ?>
>
> thanks Lidia
Here is a simple syntax
First you detect the post message. What you will do with that message
is a later question, but if there is no post message, then you can
make a printout of your form.
The form printout:
To be honest, get the names out of the database into an simple array
first. The array will be used in the form printout. Let say you have
$companyList as an global array.
Make a function for the printout.
function printCompanyList(){
global $companyList;
echo '<form name="modulo" action="response.php">';
echo '<select name="colori">';
echo '<option value="Choose a company"></option>';
foreach($companyList as $k=>$v){
echo '<option value=".$v.">'.$v.'</option>';
}
echo '</select>';
echo '</form>';
} // end of printCompanyList()
No message in the posting means that no company is chosen at the time,
thus it could be at startup time and then the application is ordered
to make this printout of company to choose from. The key value in the
post to pick will probably be "colori". This example is a simple one
to understand and not that advanced.
Post Follow-up to this messageHI!
I have yet problem with combobox and query.
COMBOBOX PAGE
This page work, I have just one problem:
With this code : " $sql =3D"select name from [db]..sysobjects where
xtype =3D 'U'order by
name";" in my combobox appear the name of all the tables of the db
but I want only few tables. how i can change this code?
//-------------------------------------------------------------------------=
=AD---------------------------------------
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$dbname =3D "[aa]";
$link =3D mssql_connect("aa", "ll", "ll")or die("Could not connect: " .
mssql_error());
mssql_select_db($dbname) or die('Could not select database');
?>
<html>
<head></head>
<body>
<?php
// SELECT FUNZIONANTE MA ESTRAE TUTTI I CAMPI
$sql =3D"select name from [db]..sysobjects where xtype =3D 'U'order by
name";
// processi la stringa $result =3D mssql_query($sql);
//verifichi il risultato se diverso da 0. Se fallisce significa che
non ci sono tabelle nel db
if (!$result) {
echo "DB Error, could not list tables\n";
echo ('MsSQL Error: ' . mssql_error());
exit;
}
?>
<table width=3D"100%" border=3D"0" cellpadding=3D"0" cellspacing=3D"0">
<tr>
<td width=3D"171">Select table </td>
<td width=3D"620">codice</td>
</tr>
<tr>
<td><form name=3D"myform" method=3D"post" action=3D"page2.php">
Tables: <select name=3D"category" onChange=3D"submit()">
<option value=3D""></option>
<?php
// cicli per estrarre tutti i nomi delle tabelle e crei direttamente
il form di scelta.
while ($row =3D mssql_fetch_row($result)) {
echo "<option value=3D\"".$row[0]."\">".$row[0]."</option>";
}
mssql_free_result($result);
?>
</select>
</form>
</td><td> </td>
</tr>
<tr><td> </td><td> </td>
</tr>
</table>
</body>
</html>
-------------------------------------------------------------------------
PAGE 2.PHP
-----------------------------
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$dbname =3D '[DB]';
$link =3D mssql_connect(dd, aa, aa)or die("Could not connect: " .
mssql_error());
mssql_select_db($dbname) or die('Could not select database');
if(isset($_POST['nome'])) {
$azienda =3D $_POST['nome'];
if($azienda =3D=3D '[Telephony Daily A]'){
$sql =3D "SELECT campo1, campo2, campo3, campo4, campo5 from
$azienda";
}else if($azienda =3D=3D "[Telephony Daily B]"){
$sql =3D "SELECT campo1, campo3, campo7, campo9, campo11 from
$azienda";
}else{
echo "errore nella definizione del nome dell'azienda'";
}
echo $sql;
}
?>
<html>
<head>
</head>
<body>
<?php
$result =3D mssql_query($sql);
//verifichi il risultato se diverso da 0. Se fallisce significa che
non ci sono tabelle nel db
if (!$result) {
echo "DB Error, could not list tables\n";
//echo 'MsSQL Error: ' . mssql_error();
exit;
}
?>
<table width=3D"100%" border=3D"1" cellpadding=3D"0" cellspacing=3D"0">
<tr><td><div align=3D"center">name/address</div></td><td><div
align=3D"center">department/surname</div></td><td><div
align=3D"center">field/history</div></td></tr>
<?php
// cicli l'array dei record per ircavare i dati
while($row =3D mssql_fetch_row($result)){
echo "<tr><td><div>s".$row[0]."</div></td><td><div>".$row[1]."</
div></
td><td><div>
".$row[2]."</div></td></tr>";
}
mssql_free_result($result);
msysql_close($link);
?>
</table>
</body>
</html>
?>
---------------------------------------------------------------------------=
=AD----
Those Are The Errors for the page2.php
Notice: Undefined variable: sql in C:\Program Files\xampp\htdocs
\intranet\page2.php on line 35
Warning: mssql_query() [function.mssql-query]: Query failed in C:
\Program Files\xampp\htdocs\intranet\page2.php on line 35
DB Error, could not list tables
The line 35 is this: $result =3D mssql_query($sql);
Thanks Lidia
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.