LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   wrong ouputs with php and mysql!! (https://www.linuxquestions.org/questions/programming-9/wrong-ouputs-with-php-and-mysql-174740/)

ulto 04-26-2004 12:04 PM

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 ??

Mara 04-26-2004 06:02 PM

Hard to say without knowing the other 2 SELECTs...

ulto 04-27-2004 02:16 PM

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

Mara 04-27-2004 05:49 PM

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)?

ulto 04-27-2004 07:26 PM

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!?

Mara 04-28-2004 04:52 PM

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.


All times are GMT -5. The time now is 12:01 PM.