LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-26-2004, 12:04 PM   #1
ulto
Member
 
Registered: Apr 2004
Posts: 52

Rep: Reputation: 1
wrong ouputs with php and mysql!!


ok below i have the following php code
im trying to match up to tables so i get a better and more descriptive output
rg instead of and number "80" i want to output " port http-web"

i thought i had it with the mysql statement below
but ouputs are wrong like they dont match at all

Domain Name Server 69
Domain Name Server 53


PHP Code:
$sql2=( "SELECT services.description FROM services,udphdr WHERE services.port = udphdr.udp_dport");
$result2 mysql_query($sql2) or die(mysql_error());
$myrow2 mysql_fetch_array($result2);


echo
"<table BORDER='2' CELLPADDING='5' align ='center'>";
echo
"<caption>UDP Header Details</caption>";
echo
"<th>Sensor ID:</th><th>CID:</th><th>UDP Source Port:</th><th>UDP Destination Port:</th><th>UDP Length:</th><th>UDP Checksum</th>";

do {
     
        
printf("<tr bgcolor=\"white\"><td>%s</td><td> %s</td><td>%s %s</td><td> %s %s</td><td> %s</td><td>%s</td></tr>"$myrow["sid"], $myrow["cid"], $myrow1["description"],$myrow["udp_sport"], $myrow2["description"], $myrow["udp_dport"], $myrow["udp_len"],  $myrow["udp_csum"]);
        


      } while ((
$myrow mysql_fetch_array($result))
    &&(
$myrow1 mysql_fetch_array($result1))&&($myrow2 mysql_fetch_array($result2))); 
so anybody know whats up with this ??
 
Old 04-26-2004, 06:02 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Hard to say without knowing the other 2 SELECTs...
 
Old 04-27-2004, 02:16 PM   #3
ulto
Member
 
Registered: Apr 2004
Posts: 52

Original Poster
Rep: Reputation: 1
Code:
$sql = ("SELECT  * FROM udphdr ");
$result = mysql_query($sql) or die(mysql_error());
$myrow = mysql_fetch_array($result);

$sql1=( "SELECT services.description FROM services, udphdr WHERE services.port = udphdr.udp_sport");
$result1 = mysql_query($sql1) or die(mysql_error());
$myrow1 = mysql_fetch_array($result1);

$sql2=( "SELECT services.description FROM services,udphdr WHERE services.port = udphdr.udp_dport");
$result2 = mysql_query($sql2) or die(mysql_error());
$myrow2 = mysql_fetch_array($result2);


echo"<table BORDER='2' CELLPADDING='5' align ='center'>";
echo"<caption>UDP Header Details</caption>";
echo"<th>Sensor ID:</th><th>CID:</th><th>UDP Source Port:</th><th>UDP Destination Port:</th><th>UDP Length:</th><th>UDP Checksum</th>";

do {
	 
        printf("<tr bgcolor=\"white\"><td>%s</td><td> %s</td><td>%s %s</td><td> %s %s</td><td> %s</td><td>%s</td></tr>", $myrow["sid"], $myrow["cid"], $myrow1["description"],$myrow["udp_sport"], $myrow2["description"], $myrow["udp_dport"], $myrow["udp_len"],  $myrow["udp_csum"]);
		


      } while (($myrow = mysql_fetch_array($result))
	&&($myrow1 = mysql_fetch_array($result1))&&($myrow2 = mysql_fetch_array($result2)));
ok there are the other 2 select statement, hope it helps
 
Old 04-27-2004, 05:49 PM   #4
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
The results of the queries have no 'link' between them and the three results are correct, but they can go in any order. I think there can be only one SELECT used, but I don't understand the meaning fully so I don't know how to write it. COuld you explain what you'd like to get exactly (what should be the connections between results of the three queries)?
 
Old 04-27-2004, 07:26 PM   #5
ulto
Member
 
Registered: Apr 2004
Posts: 52

Original Poster
Rep: Reputation: 1
well one of the statements just outputs all info from a database while the other 2 are doing the same thing as each other.

i want to match up data in the udphdr table with the services table (both in the same database)

instead of getting an output of lets say 80 i want to take that 80 and match it up with what the services tables says what 80 represents via the field description

i kinda know why i have to only use one select statement thought by doing it this way would work too but how do i go about using one select statement

i think if i do some kind of order in them i might be able to match and link them up what do ye think!?
 
Old 04-28-2004, 04:52 PM   #6
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
I think that the query may be
Code:
SELECT udphdr.cid, udphdr.sid, udphdr.udp_sport, udphdr.udp_dport,
             udphdr.udp_len, udphdr.udp_csum sdesc.description, sdest.description
FROM udphdr, description AS sdesc, description AS sdest
WHERE sdesc.port=udphdr.udp_sport AND sdest.port=udphdr.udp_dport
Not tested, you should check if mysql allows you to run such a query, but I don't see any reason it shouldn't.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql-server4.1 and mod php-mysql conflig kernelvn *BSD 0 06-18-2005 11:52 AM
Problem getting PHP to recognize MySQL, Using PHP 4.0 and MySQL 4.0.20 d2army Programming 4 06-27-2004 08:54 PM
php4 mysql, installation, php-pages with mysql info stay empty dnla Linux - Software 2 03-14-2004 02:54 PM
Apache Mysql Php: mysql with php doesn't work breakerfall Linux - Networking 6 12-27-2003 08:59 PM
php and mySQL dates before a sudden year go wrong??? Satriani Linux - Software 2 04-29-2003 03:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration