Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

combobox and print query

 
   Database Help (Home) -> PHP SQL RSS
Next:  Adding text inside the code  
Author Message
lidlid

External


Since: Mar 07, 2008
Posts: 1



(Msg. 1) Posted: Fri Mar 07, 2008 3:01 am
Post subject: combobox and print query
Archived from groups: alt>php>sql (more info?)

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

 >> Stay informed about: combobox and print query 
Back to top
Login to vote
LAMP-MAN

External


Since: Mar 05, 2008
Posts: 2



(Msg. 2) Posted: Fri Mar 07, 2008 6:28 am
Post subject: Re: combobox and print query [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Mar 7, 12:01 pm, 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.

 >> Stay informed about: combobox and print query 
Back to top
Login to vote
Lid

External


Since: Mar 18, 2008
Posts: 1



(Msg. 3) Posted: Tue Mar 18, 2008 2:39 am
Post subject: Re: combobox and print query [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

HI!

I have yet problem with combobox and query.

COMBOBOX PAGE

This page work, I have just one problem:
With this code : " $sql ="select name from [db]..sysobjects where
xtype = '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?
//-------------------------------------------------------------------------­---------------------------------------
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);


$dbname = "[aa]";
$link = 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 ="select name from [db]..sysobjects where xtype = 'U'order by
name";


// processi la stringa $result = 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="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="171">Select table </td>
<td width="620">codice</td>
</tr>
<tr>
<td><form name="myform" method="post" action="page2.php">
Tables: <select name="category" onChange="submit()">
<option value=""></option>


<?php


// cicli per estrarre tutti i nomi delle tabelle e crei direttamente
il form di scelta.
while ($row = mssql_fetch_row($result)) {
echo "<option value=\"".$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 = '[DB]';
$link = 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 = $_POST['nome'];
if($azienda == '[Telephony Daily A]'){
$sql = "SELECT campo1, campo2, campo3, campo4, campo5 from
$azienda";


}else if($azienda == "[Telephony Daily B]"){


$sql = "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 = 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="100%" border="1" cellpadding="0" cellspacing="0">
<tr><td><div align="center">name/address</div></td><td><div
align="center">department/surname</div></td><td><div
align="center">field/history</div></td></tr>
<?php


// cicli l'array dei record per ircavare i dati
while($row = 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>


?>
---------------------------------------------------------------------------­----


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 = mssql_query($sql);


Thanks Lidia
 >> Stay informed about: combobox and print query 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
delete header on print - Hi, I have a php script that create html page. that I have to print. I want to know how to delete header and footer on print. Can you help me Thank.

How can i Optimize sql Query ? - Hi, I'd like to optimize this query: Code: SELECT * FROM `links` WHERE active = "1" AND mainweight != 0 ORDER BY Rand()*(1/mainweight) LIMIT 5 I have a database of links wich has 3 000 rows. I'd like to select weighted random links from ...

Mysql query cache? - Hello. I have a strange problem with my website at work. There is a database with some product data. Data is registered thru php - website, and once a week a raport is generated from this data. If a mistake was made, the data of current week can be..

function problem involving query - I'm trying to construct a database of old houses including the parts they are made of as roof construction, floor construction, types of windows, vaults, etc. To do that I set up several tables. One containing the house id, address, last visit, etc. For....

PHPtriad v2.2.1 removal - When I fist started using apache/php/mysql I used phptriad [a wonderful piece of kit] to get me up and running. I've used this ever since. I'm think inow of 'upgrading' to laters versions of all three applications, and have found various tutorials/Ho...
   Database Help (Home) -> PHP SQL All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]