Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

combobox and print query
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



Report this thread to moderator Post Follow-up to this message
Old Post
lidlid@gmail.com
03-07-08 01:06 PM


Re: combobox and print query
On 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.


Report this thread to moderator Post Follow-up to this message
Old Post
LAMP-MAN
03-08-08 03:04 AM


Re: combobox and print query
HI!

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

Report this thread to moderator Post Follow-up to this message
Old Post
Lid
03-18-08 01:06 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP SQL archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 10:30 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.