473,394 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Need help with outer join command

I have a database called inventory, In it I have tables called network and environment. In the network table there is a row called ipaddr. I would like to be able to write a query that can find ip address, lets say 10.0.0.1 in the table called network, row called ipaddr, join the information with environment table and display the search result. I want to be able to search the inventory database by ip address and be able to see the complete result, based on data in both tables. What would be the statement ?
Sep 11 '07 #1
9 1967
Atli
5,058 Expert 4TB
Hi. Welcome to TSDN!

Consider this example...

Say we have a database for a simple blog system:
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE User (
  2.   UserID Int Unsigned Auto_Increment Primary Key,
  3.   Name VarChar(150) Not Null
  4. );
  5.  
  6. CREATE TABLE Blogg (
  7.   BloggID Int Unsigned Auto_Increment Primary Key,
  8.   Title VarChar(255),
  9.   Body Text,
  10.   Owner BigInt References User(UserID)
  11. );
  12.  
Now if I wanted to find all Blogs written by a single user, along with the user info, I could do this:
Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.   Blog.Title, Blog.Body,
  3.   User.UserID, User.Name
  4. FROM User
  5. INNER JOIN Blog
  6.   ON User.UserID = Blog.Owner
  7.  
Sep 11 '07 #2
Thank you for that reply. Now I would like to add a search box to my wiki page and have users query the data by ipaddr string. Somehow I need to pass the string from the webpage to mysql and display the results back. Any ideas
Sep 11 '07 #3
Atli
5,058 Expert 4TB
What kind of API are you using on your page?
PHP?... ASP?... Something else?
Sep 11 '07 #4
What kind of API are you using on your page?
PHP?... ASP?... Something else?

I am using PHP
999999999999999999999999999999999999999999999
Sep 12 '07 #5
Atli
5,058 Expert 4TB
Then you simply need to create a HTML form which sends the data to you PHP script, have your PHP script execute a query on your database and display the results.

If you are having difficulties passing the data from the form, check out this article I wrote on the subject.

If you need to know how to query the database, check out the MySQL Functions, or better yet, the Improved MySQL Extension at php.net
Sep 12 '07 #6
Then you simply need to create a HTML form which sends the data to you PHP script, have your PHP script execute a query on your database and display the results.

If you are having difficulties passing the data from the form, check out this article I wrote on the subject.

If you need to know how to query the database, check out the MySQL Functions, or better yet, the Improved MySQL Extension at php.net
here is the script I created, but when I execute it, nothing comes back in a webpage, it still displays the search button, I am thinking something is not correct in the way I try to display results.
[PHP]<?php

if($_GET["field1"]):

// Connecting, selecting database
$link = mysql_connect('10.10.17.247', 'edefikh', 'changeme')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('InventoryDev') or die('Could not select database');

// Performing SQL query
$query = 'SELECT network.hostname, server.domain, server.manufacturer, server.model, server.chassis, server.slot, server.os, server.osver, server.notes
FROM network
LEFT OUTER JOIN server
ON network.serverid = server.serverid
WHERE ipaddr = '.mysql_escape_string($_GET["ipadd"]);

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);

else:
?>

<!-- comments -->
<form method="post" action="test.php">
<input type ="text" name ="ipadd"/>
<input name="button" value="Search" type="SUBMIT"/>
</form>

<?php endif;?>[/PHP]
Sep 14 '07 #7
mwasif
802 Expert 512MB
Use CODE tags when posting souce code.
Sep 14 '07 #8
Atli
5,058 Expert 4TB
PHP does not use : like python and other such languages do...

Your if statements should be structured like this:
Expand|Select|Wrap|Line Numbers
  1. if($something > 1) {
  2.   echo "It's bigger than 1";
  3. }
  4. else if($something == 1) {
  5.   echo "It is 1";
  6. }
  7. else {
  8.   echo "It's less than 1";
  9. }
  10.  
PHP shows error messages when you make syntax errors like these. You just need to turn them on.
Sep 14 '07 #9
I need to be able to query a set of 7 tables, pull the right data from it and then display the result in a table. Here is what I have so far, I am not sure how to display the results nicely:


<?php
if($_POST["ipadd"]):
$_POST["my_dropdown"];
echo mysql_escape_string($_POST['text']);
echo $_POST['my_dropdown'];

// Connecting, selecting database
$link = mysql_connect('10.10.17.247', 'inventory', 'inventory')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('InventoryDev') or die('Could not select database');


// Performing SQL query
$query = "SELECT network.hostname, server.domain, server.manufacturer, server.model, server.chassis, server.slot, server.os, server.osver, server.notes
FROM network
LEFT OUTER JOIN server
ON network.serverid = server.serverid
WHERE ipaddr = '" . mysql_escape_string($_POST["ipadd"]) . "'";

print "<p>$query<p>\n";

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);

else:
?>

<!-- comments -->
<form method="post" action="test.php">
<input type ="text" name ="ipadd"/>
<p><select size="1" name="my_dropdown">
<option value="one">cpu</option>
<option value="two">disk</option>
<option value="three">environment</option>
<option value="four">memory</option>
<option value="five">network</option>
<option value="six">product</option>
<option value="seven">server</option>
</select></p>
<input name="button" value="Search" type="SUBMIT" name="btm_submit" onclick="validate()"/>
</form>



<?php endif;?>
Sep 20 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Justin Hennessy | last post by:
Hi all, I am working with a computer hardware asset database and I am trying to get information out of it for each PC in my organisation. Here is the basic table structure: Table1 -> Table2...
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
3
by: Prem | last post by:
Hi, I am having many problems with inner join. my first problem is : 1) I want to know the precedance while evaluating query with multiple joins. eg. select Employees.FirstName,...
2
by: Sonal Jain | last post by:
i have a query which goes like this:- select a.col1,b.col2,c.col2 from tab1 a,tab2 b,tab3 c where a.col1 *= b.col1 and a.col2 *= c.col2 and b.col3 = c.col3 how do I write this query in SQL...
1
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins"...
1
by: MK Randall | last post by:
We're losing a Sybase datasource and need to pull from an identical DB2 database until the SQL Server becomes available later on this year. If someone could read through the query and let me know...
5
by: Bob Stearns | last post by:
When I run the following query with the two sections commented out, the response time is between 1 an 2 seconds; with the first indicated section enabled, the response goes up to 15 seconds even...
14
by: mike | last post by:
I'm using postgresl 7.3.2 and have a query that executes very slowly. There are 2 tables: Item and LogEvent. ItemID (an int4) is the primary key of Item, and is also a field in LogEvent. Some...
1
by: imranpariyani | last post by:
Hi i have a severe performance problem with one of my views which has 6 to 8 joins .. any help will be appreciated.. the view is: CREATE OR REPLACE VIEW thsn.trade_view AS SELECT...
8
by: SAL | last post by:
Hello, Using the designer in my project, I created a DataTable for one of the tables in an Access database. I created a TableAdapter for that DataTable by adding queries. For the most part, the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.