03-24-2009
add the output of a query to a variable to be used in another query
I would like to use the result of a query in another query. How do I redirect/add the output to another variable?
PHP Code:
$result = odbc_exec($connect, $query);
while ($row = odbc_fetch_array($result)) {
echo $row["host"],"\n";
}
odbc_close($connect);
?>
This will output hostnames:
host1 host2 host3
I would like to add the output to the variable $hosts something like this:
$hosts = "host1,host2,host3"
I plan to use $host in another query further down in the script.
thanks & regards
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
My requirement is :
We are calling an sql statement from a UNIX session, and fetching data into some variables from a table .. now we are unable to access these variables from outside the SQL part. Please let me know how can I achieve this.
Can you please share a code snippet which... (4 Replies)
Discussion started by: venkatesh_sasi
4 Replies
2. UNIX for Dummies Questions & Answers
Hi,
I wanted to o/p the number of rows in a table to a variable in linux. How can i achieve this.
I wrote the query and its settings like feedback, pagesize line size in a file and using this file as a parameter to the sqlplus command. now can i redirect the o/p of that query to a variable.... (2 Replies)
Discussion started by: Swapna173
2 Replies
3. Solaris
Hi Everyone,
When i issue command like
ls -l | awk '/udtts/ {print $9}'
===============================
I am getting output as
udttsGEHLNAR.6864
udttsGEHLNAR.7921
udttsNARALAX.15415
udttsNARALAX.18016
But I want output after dot i.e like
6864
7921
15415
18016 (3 Replies)
Discussion started by: gehlnar
3 Replies
4. Shell Programming and Scripting
Hi,
I have a requirement as below which needs to be done viz UNIX shell script
(1) I have to connect to an Oracle database
(2) Exexute "SELECT field_status from table 1" query on one of the tables.
(3) Based on the result that I get from point (2), I have to update another table in the... (6 Replies)
Discussion started by: balaeswari
6 Replies
5. Shell Programming and Scripting
My script contains as follows,
VALUE=`sqlplus un/pwd <<EOF > OB.txt
set pagesize 0 feedback off verify off heading off echo off
select max(1) from table1;
exit;
EOF`
insert into table2 values(1, 'The max value is $value',...);
i need the value of VALUE to be inserted after 'The max... (2 Replies)
Discussion started by: savithavijay
2 Replies
6. Shell Programming and Scripting
Hi,
I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database.
For instance:
USER CITY
--------- ----------
A CITY_A
B CITY_B
C ... (2 Replies)
Discussion started by: DevendraG
2 Replies
7. UNIX for Dummies Questions & Answers
I was performing the wc -l operation in one data file the result is less when i was giving -nu on the view of the file.
while giving wc -l the count is 5023
after setting line numbers in view of file is giving 5024.
Can anyone help on this.... (5 Replies)
Discussion started by: abhii
5 Replies
8. Shell Programming and Scripting
Hi,
I need to get a variable HMAX_TBL_ID and then use it in second select query. The first select statement returns few leading white spaces for ex : 12345
so when I run the script HMAX_TBL_ID does not return the "12345" , it returns blank.
Please let me know what I am missing.
... (1 Reply)
Discussion started by: sandy162
1 Replies
9. Shell Programming and Scripting
Hi All,
How to pass date variable to a query?
I have tried the below one , but it's not working.
ost.ksh
#!/bin/ksh
v_date=$1
var=$(sqlplus -s $ORACON <<ENDOFSQL
SELECT TO_DATE('$v_date','DD-MON-YYYY'),-1) FROM DUAL;
exit;
ENDOFSQL
)
#End
I have executed as below. (7 Replies)
Discussion started by: ROCK_PLSQL
7 Replies
10. Shell Programming and Scripting
Hi
iam new to shell scripting
how to declare variables as redshift query and I have to compare two counts by using if condition .
ex:count=select count(*) from prd;
select count(*) from prd;
select count(*) from tag;
can any one help me .
Please use CODE tags when displaying... (1 Reply)
Discussion started by: sam526
1 Replies
LEARN ABOUT PHP
mssql_result
MSSQL_RESULT(3) MSSQL_RESULT(3)
mssql_result - Get result data
SYNOPSIS
string mssql_result (resource $result, int $row, mixed $field)
DESCRIPTION
mssql_result(3) returns the contents of one cell from a MS SQL result set.
PARAMETERS
o $result
- The result resource that is being evaluated. This result comes from a call to mssql_query(3).
o $row
- The row number.
o $field
- Can be the field's offset, the field's name or the field's table dot field's name (tablename.fieldname). If the column name has
been aliased ('select foo as bar from...'), it uses the alias instead of the column name.
Note
Specifying a numeric offset for the $field argument is much quicker than specifying a fieldname or tablename.fieldname argu-
ment.
RETURN VALUES
Returns the contents of the specified cell.
EXAMPLES
Example #1
mssql_result(3) example
<?php
// Send a select query to MSSQL
$query = mssql_query('SELECT [username] FROM [php].[dbo].[userlist]');
// Check if there were any records
if (!mssql_num_rows($query)) {
echo 'No records found';
} else {
for ($i = 0; $i < mssql_num_rows($query); ++$i) {
echo mssql_result($query, $i, 'username'), PHP_EOL;
}
}
// Free the query result
mssql_free_result($query);
?>
The above example will output something similar to:
Kalle
Felipe
Emil
Ross
Example #2
Faster alternative to above example
<?php
// Send a select query to MSSQL
$query = mssql_query('SELECT [username] FROM [php].[dbo].[userlist]');
// Check if there were any records
if (!mssql_num_rows($query)) {
echo 'No records found';
} else {
while ($row = mssql_fetch_array($query)) {
echo $row['username'], PHP_EOL;
}
}
// Free the query result
mssql_free_result($query);
?>
NOTES
Note
When working on large result sets, you should consider using one of the functions that fetch an entire row (specified below). As
these functions return the contents of multiple cells in one function call, they're MUCH quicker than mssql_result(3).
SEE ALSO
Recommended high-performance alternatives: mssql_fetch_row(3), mssql_fetch_array(3), mssql_fetch_assoc(3), mssql_fetch_object(3).
PHP Documentation Group MSSQL_RESULT(3)