zenag Posted April 30, 2008 Share Posted April 30, 2008 regarding $sql1 we can assign it.variable can be of any type...nothing problem in that... and...below query is correct it works fine and regardng.. while ($row1=mysql_fetch_row($result2))( $uuid=$row1[0]; echo $uuid; } $result3 = mysql_query("SELECT users.firstname,users.surname,incidents.owner_id FROM incidents,users where (incidents.owner_id = users.id) OR (incidents.owner_id <'$uuid') OR (incidents.owner_id = NULL)",$link); Quote Link to comment Share on other sites More sharing options...
tuxbuddy Posted April 30, 2008 Author Share Posted April 30, 2008 See I have made changes...HEre goes the complete COde: <? session_start(); $clicked=$_POST["gender"]; ?><? if($clicked=="open") { ?> <html> <title> Welcome to Project Management Tool</title> <body bgcolor=#AFC7C7> <h1> Report</h1> <?php $myusername = $_SESSION['myusername']; echo $myusername; //put the above right at the top of your script. Everything else can follow ?> <? //header("Content-Type: text/plain"); /* set's the variables for MySQL connection */ $server = "localhost"; // this is the server address and port $username = "root"; // change this to your username $password = "mysql123"; // change this to your password /* Connects to the MySQL server */ $link = @mysql_connect ($server, $username, $password) or die (mysql_error()); /* Defines the Active Database for the Connection */ if (!@mysql_select_db("helpcore", $link)) { echo "<p>There has been an error. This is the error message:</p>"; echo "<p><strong>" . mysql_error() . "</strong></p>"; echo "Please Contact Your Systems Administrator with the details"; } $sql1 = mysql_query("SELECT id from users where loginname ='".$myusername."'",$link); while($row=mysql_fetch_row($sql1 )) { #echo $result[0]; $uid=$row[0]; echo $uid; #$uid=$result["id"]; #echo "$uid"; } #$result2 = mysql_query("SELECT incidents.id, incidents.description, users.firstname, users.surname, users.loginname FROM incidents,users WHERE (incidents.owner_id = users.id) AND (incidents.contact_id = '".$result[0]."')", $link); $result2 = mysql_query("SELECT id, description FROM incidents where contact_id = '".$uid."'", $link); #echo ("SELECT incidents.id, incidents.description, users.firstname, users.surname, users.loginname FROM incidents,users WHERE (incidents.owner_id = users.id) OR (incidents.contact_id = '".$uid."')"; echo $result2 ; #$result2 = mysql_query("SELECT incidents.id,incidents.description,users.firstname,users.surname,users.loginname from incidents,users where (incidents.owner_id = users.id) OR (incidents.contact_id = '".$uid."')", $link); while ($row1=mysql_fetch_row($result2))( $uuid=$row1[0]; echo $uuid; #$result3 = mysql_query("SELECT users.firstname,users.surname,incidents.owner_id FROM incidents,users where (incidents.owner_id = users.id) OR (incidents.owner_id = NULL) $result3 = mysql_query("SELECT users.firstname,users.surname,incidents.owner_id FROM incidents,users where (incidents.owner_id = users.id) OR (incidents.owner_id <'$uuid') OR (incidents.owner_id = NULL)",$link); if (!$result3) { echo("<p>Error performing query: " . mysql_error() . "</p>"); exit(); } /* Starts the table and creates headings */ ?> <table border="1"> <tr> <td><strong>ID</strong></td> <td><strong>Description</strong></td> <td><strong>Owner Name</strong></td> <td><strong>Notes</strong></td> <? /* Retrieves the rows from the query result set and puts them into a HTML table row */ /* Retrieves the rows from the query result set and puts them into a HTML table row */ #echo "hello"; #echo "$myusername"; while ($row = mysql_fetch_array($result3, MYSQL_ASSOC)) { echo "\n"; echo("<tr>\n<td>" . $row["id"] . "</td>"); echo("<td>" . $row["description"] . "</td>"); echo("<td>" . $row["firstname"] . $row["surname"]. "</td>"); echo("<td>" . $row["loginname"] . "</td></tr>"); # echo("<td>" . $row["name"] . "</td>"); # echo("<td>" . $row["create_time"] . "</td>"); } /* Closes the table */ ?> </table> <? /* Closes Connection to the MySQL server */ mysql_close ($link); } else { if($clicked=="closed") { echo "closed"; } } ?> IS it allright?? Quote Link to comment Share on other sites More sharing options...
tuxbuddy Posted April 30, 2008 Author Share Posted April 30, 2008 Not working Quote Link to comment Share on other sites More sharing options...
tuxbuddy Posted April 30, 2008 Author Share Posted April 30, 2008 Sorry Forgot to change : row to row1 everywhere: while ($row1 = mysql_fetch_array($result3, MYSQL_ASSOC)) { echo "\n"; echo("<tr>\n<td>" . $row1["id"] . "</td>"); echo("<td>" . $row1["description"] . "</td>"); echo("<td>" . $row1["firstname"] . $row["surname"]. "</td>"); echo("<td>" . $row1["loginname"] . "</td></tr>"); But Still its not working...Can yu check code for me?/ Quote Link to comment Share on other sites More sharing options...
zenag Posted April 30, 2008 Share Posted April 30, 2008 have u changed $row1 in every while statement??? like this.. while($row1=mysql_fetch_row($result)) { while ($row1=mysql_fetch_row($result2)){ if so ...change it...to different variable...$row,$row1 Quote Link to comment Share on other sites More sharing options...
tuxbuddy Posted April 30, 2008 Author Share Posted April 30, 2008 Sorry I fixed it...missed { } sign near while loop. Now its showing some o/P like this: Report venkat 9Resource id #4383935ID Description Owner Name Notes Ad.Administrator Ad.Administrator Ad.Administrator Ad.Administrator PrasanthM PrasanthM PrasanthM PrasanthM SijoJose SijoJose SijoJose SijoJose I think something going wrong..with query presentation Quote Link to comment Share on other sites More sharing options...
zenag Posted April 30, 2008 Share Posted April 30, 2008 it cause of loop problem....some braces have to be checked or can u send full code Quote Link to comment Share on other sites More sharing options...
tuxbuddy Posted April 30, 2008 Author Share Posted April 30, 2008 Here is the complete code: <? session_start(); $clicked=$_POST["gender"]; ?><? if($clicked=="open") { ?> <html> <title> Welcome to Project Management Tool</title> <body bgcolor=#AFC7C7> <h1> Report</h1> <?php $myusername = $_SESSION['myusername']; echo $myusername; //put the above right at the top of your script. Everything else can follow ?> <? //header("Content-Type: text/plain"); /* set's the variables for MySQL connection */ $server = "localhost"; // this is the server address and port $username = "root"; // change this to your username $password = "mysql123"; // change this to your password /* Connects to the MySQL server */ $link = @mysql_connect ($server, $username, $password) or die (mysql_error()); /* Defines the Active Database for the Connection */ if (!@mysql_select_db("helpcore", $link)) { echo "<p>There has been an error. This is the error message:</p>"; echo "<p><strong>" . mysql_error() . "</strong></p>"; echo "Please Contact Your Systems Administrator with the details"; } $sql1 = mysql_query("SELECT id from users where loginname ='".$myusername."'",$link); while($row=mysql_fetch_row($sql1 )) { #echo $result[0]; $uid=$row[0]; echo $uid; #$uid=$result["id"]; #echo "$uid"; } #$result2 = mysql_query("SELECT incidents.id, incidents.description, users.firstname, users.surname, users.loginname FROM incidents,users WHERE (incidents.owner_id = users.id) AND (incidents.contact_id = '".$result[0]."')", $link); $result2 = mysql_query("SELECT id, description FROM incidents where contact_id = '".$uid."'", $link); #echo ("SELECT incidents.id, incidents.description, users.firstname, users.surname, users.loginname FROM incidents,users WHERE (incidents.owner_id = users.id) OR (incidents.contact_id = '".$uid."')"; echo $result2 ; #$result2 = mysql_query("SELECT incidents.id,incidents.description,users.firstname,users.surname,users.loginname from incidents,users where (incidents.owner_id = users.id) OR (incidents.contact_id = '".$uid."')", $link); while ($row1=mysql_fetch_row($result2)){ $uuid=$row1[0]; echo $uuid; } #$result3 = mysql_query("SELECT users.firstname,users.surname,incidents.owner_id FROM incidents,users where (incidents.owner_id = users.id) OR (incidents.owner_id = NULL) $result3 = mysql_query("SELECT users.firstname,users.surname,incidents.owner_id FROM incidents,users where (incidents.owner_id = users.id) OR (incidents.owner_id < '$uuid') OR (incidents.owner_id = NULL)",$link); if (!$result3) { echo("<p>Error performing query: " . mysql_error() . "</p>"); exit(); } } /* Starts the table and creates headings */ ?> <table border="1"> <tr> <td><strong>ID</strong></td> <td><strong>Description</strong></td> <td><strong>Owner Name</strong></td> <td><strong>Notes</strong></td> <? /* Retrieves the rows from the query result set and puts them into a HTML table row */ /* Retrieves the rows from the query result set and puts them into a HTML table row */ #echo "hello"; #echo "$myusername"; while ($row1 = mysql_fetch_array($result3, MYSQL_ASSOC)) { echo "\n"; echo("<tr>\n<td>" . $row1["id"] . "</td>"); echo("<td>" . $row1["description"] . "</td>"); echo("<td>" . $row1["firstname"] . $row1["surname"]. "</td>"); echo("<td>" . $row1["loginname"] . "</td></tr>"); # echo("<td>" . $row["name"] . "</td>"); # echo("<td>" . $row["create_time"] . "</td>"); } /* Closes the table */ ?> </table> <? /* Closes Connection to the MySQL server */ /* Closes Connection to the MySQL server */ mysql_close ($link); } else { if($clicked=="closed") { echo "closed"; } } ?> Quote Link to comment Share on other sites More sharing options...
tuxbuddy Posted April 30, 2008 Author Share Posted April 30, 2008 What I guess is select statement??? Quote Link to comment Share on other sites More sharing options...
tuxbuddy Posted April 30, 2008 Author Share Posted April 30, 2008 Heyy...I think we are close to right output.See here it displays: venkat 9Resource id #4383935ID Description Owner Name Notes Ad.Administrator Ad.Administrator Ad.Administrator ChandrappaChikkanna I think ID Description are not being retrieved in the right way But 38 39 and 35 are the right output.Can u put them in ID and Description in the right manner Quote Link to comment Share on other sites More sharing options...
zenag Posted April 30, 2008 Share Posted April 30, 2008 this solves all ur probs..... <? session_start(); $clicked=$_POST["gender"]; ?><? if($clicked=="open") { ?> <html> <title> Welcome to Project Management Tool</title> <body bgcolor=#AFC7C7> <h1> Report</h1> <?php $myusername = "administrator"; echo $myusername; //put the above right at the top of your script. Everything else can follow ?> <? //header("Content-Type: text/plain"); /* set's the variables for MySQL connection */ $server = "localhost"; // this is the server address and port $username = "root"; // change this to your username $password = ""; // change this to your password /* Connects to the MySQL server */ $link = @mysql_connect ($server, $username, $password) or die (mysql_error()); /* Defines the Active Database for the Connection */ if (!@mysql_select_db("helpcore", $link)) { echo "<p>There has been an error. This is the error message:</p>"; echo "<p><strong>" . mysql_error() . "</strong></p>"; echo "Please Contact Your Systems Administrator with the details"; } $sql1 = mysql_query("SELECT id from users where loginname ='".$myusername."'",$link); while($row=mysql_fetch_row($sql1 )) { #echo $result[0]; $uid=$row[0]; echo $uid; #$uid=$result["id"]; #echo "$uid"; } #$result2 = mysql_query("SELECT incidents.id, incidents.description, users.firstname, users.surname, users.loginname FROM incidents,users WHERE (incidents.owner_id = users.id) AND (incidents.contact_id = '".$result[0]."')", $link); $result2 = mysql_query("SELECT id, description FROM incidents where contact_id = '".$uid."'", $link); #echo ("SELECT incidents.id, incidents.description, users.firstname, users.surname, users.loginname FROM incidents,users WHERE (incidents.owner_id = users.id) OR (incidents.contact_id = '".$uid."')"; //echo $result2 ; #$result2 = mysql_query("SELECT incidents.id,incidents.description,users.firstname,users.surname,users.loginname from incidents,users where (incidents.owner_id = users.id) OR (incidents.contact_id = '".$uid."')", $link); while ($row1=mysql_fetch_row($result2)){ $uuid=$row1[0]; echo $uuid; } #$result3 = mysql_query("SELECT users.firstname,users.surname,incidents.owner_id FROM incidents,users where (incidents.owner_id = users.id) OR (incidents.owner_id = NULL) $result3 = mysql_query("SELECT users.firstname,incidents.description,users.surname,incidents.owner_id FROM incidents,users where (incidents.owner_id = users.id) OR (incidents.owner_id < '$uuid') OR (incidents.owner_id = NULL)",$link); //echo "SELECT users.firstname,users.surname,incidents.owner_id FROM incidents,users where (incidents.owner_id = users.id) OR (incidents.owner_id < '$uuid') OR (incidents.owner_id = NULL)"; if (!$result3) { echo("<p>Error performing query: " . mysql_error() . "</p>"); exit(); } /* Starts the table and creates headings */ ?> <table border="1"> <tr> <td><strong>ID</strong></td> <td><strong>Description</strong></td> <td><strong>Owner Name</strong></td> <td><strong>Notes</strong></td> <? /* Retrieves the rows from the query result set and puts them into a HTML table row */ /* Retrieves the rows from the query result set and puts them into a HTML table row */ #echo "hello"; #echo "$myusername"; while ($row2 = mysql_fetch_array($result3)) { echo "\n"; echo("<tr>\n<td>" . $row2["owner_id"] . "</td>"); echo("<td>" . $row2["description"] . "</td>"); echo("<td>" . $row2["firstname"] . $row1["surname"]. "</td>"); echo("<td>" . $row2["loginname"] . "</td></tr>"); # echo("<td>" . $row["name"] . "</td>"); # echo("<td>" . $row["create_time"] . "</td>"); } /* Closes the table */ ?> </table> <? /* Closes Connection to the MySQL server */ /* Closes Connection to the MySQL server */ mysql_close ($link); } else { if($clicked=="closed") { echo "closed"; } } ?> Quote Link to comment Share on other sites More sharing options...
zenag Posted April 30, 2008 Share Posted April 30, 2008 ive changed these lines... $myusername = "administrator"; echo $myusername; for my convenience .... change it to $myusername = $_SESSION['myusername']; echo $myusername; Quote Link to comment Share on other sites More sharing options...
tuxbuddy Posted April 30, 2008 Author Share Posted April 30, 2008 Heyy...One iSse still unsolved. See 38 39 and 36 which it displays is all I want.But..Under table , it shows: ID Description Owner Name Notes 17 asdfzsvgfsd Ad.Administrator 26 test1 ChandrappaChikkanna 13 at Ad.Administrator 24 test Ad.Administrator Thats incorrect.What I want the corresponding entry relative to 38 39 and 36 only. Quote Link to comment Share on other sites More sharing options...
zenag Posted April 30, 2008 Share Posted April 30, 2008 since u have selected only four fields here.. $result3 = mysql_query("SELECT users.firstname,incidents.description,users.surname,incidents.owner_id FROM incidents,users where (incidents.owner_id = users.id) OR (incidents.owner_id < '$uuid') OR (incidents.owner_id = NULL)",$link); it would display that selected fields only....if u need to select all fields from two tables u can write it as... SELECT * FROM incidents,users where ... Quote Link to comment Share on other sites More sharing options...
tuxbuddy Posted April 30, 2008 Author Share Posted April 30, 2008 Ok...Leave it ...What I actlly want from you is Just display like this: ID DEscrition OwnerName Notes 38 ... .. 39 ... .. 36 .. .. For that the hint I think will work is : $sql1 = mysql_query("SELECT id from users where loginname ='".$myusername."'",$link); while($row=mysql_fetch_row($sql1 )) { #echo $result[0]; $uid=$row[0]; #echo $uid; #$uid=$result["id"]; #echo "$uid"; } #$result2 = mysql_query("SELECT incidents.id, incidents.description, users.firstname, users.surname, users.loginname FROM incidents,users WHERE (incidents.owner_id = users.id) AND (incidents.contact_id = '".$result[0]."')", $link); $result2 = mysql_query("SELECT id, description FROM incidents where contact_id = '".$uid."'", $link); #echo ("SELECT incidents.id, incidents.description, users.firstname, users.surname, users.loginname FROM incidents,users WHERE (incidents.owner_id = users.id) OR (incidents.contact_id = '".$uid."')"; #echo $result2 ; #$result2 = mysql_query("SELECT incidents.id,incidents.description,users.firstname,users.surname,users.loginname from incidents,users where (incidents.owner_id = users.id) OR (incidents.contact_id = '".$uid."')", $link); while ($row1=mysql_fetch_row($result2)){ $uuid=$row1[0]; echo $uuid; } #$result3 = mysql_query("SELECT users.firstname,users.surname,incidents.owner_id FROM incidents,users where (incidents.owner_id = users.id) OR (incidents.owner_id = NULL) $result2 = mysql_query("SELECT incidents.id,incidents.description,users.firstname,users.surname,incidents.owner_id FROM incidents,users where (incidents.owner_id = users.id) OR (incidents.owner_id = '$uuid') OR (incidents.owner_id = NULL)",$link); if (!$result2) { echo("<p>Error performing query: " . mysql_error() . "</p>"); exit(); } /* Starts the table and creates headings */ ?> <table border="1"> <tr> <td><strong>ID</strong></td> <td><strong>Description</strong></td> <td><strong>Owner Name</strong></td> <td><strong>Notes</strong></td> <? /* Retrieves the rows from the query result set and puts them into a HTML table row */ /* Retrieves the rows from the query result set and puts them into a HTML table row */ #echo "hello"; #echo "$myusername"; while ($row1 = mysql_fetch_array($result2, MYSQL_ASSOC)) { echo "\n"; echo("<tr>\n<td>" . $row1["id"] . "</td>"); echo("<td>" . $row1["description"] . "</td>"); echo("<td>" . $row1["firstname"] . $row1["surname"]. "</td>"); echo("<td>" . $row1["loginname"] . "</td></tr>"); # echo("<td>" . $row["name"] . "</td>"); # echo("<td>" . $row["create_time"] . "</td>"); } /* Closes the table */ ?> </table> <? /* Closes Connection to the MySQL server */ mysql_close ($link); WIll it work???I tried but the same o/p as before Quote Link to comment Share on other sites More sharing options...
zenag Posted April 30, 2008 Share Posted April 30, 2008 query hasnt yet accepted .." incidents.owner_id=NULL "..its not working ,we cannot display fields from two tables by satisfying condition from single table (ie.incidents.owner_id satisfies only incidents table but not users).if the condition satisfies both tables only we can able to display fields from both tables.. Quote Link to comment Share on other sites More sharing options...
tuxbuddy Posted April 30, 2008 Author Share Posted April 30, 2008 Check ur Mail...I want to clearly make u understand what Actlly I want,,,Check ur mail. Quote Link to comment Share on other sites More sharing options...
tuxbuddy Posted April 30, 2008 Author Share Posted April 30, 2008 DOne...I have explain you with screenshots.Kindly check. Quote Link to comment Share on other sites More sharing options...
zenag Posted April 30, 2008 Share Posted April 30, 2008 query hasnt yet accepted .." incidents.owner_id=NULL "..its not working ,we cannot display fields from two tables by satisfying condition from single table (ie.incidents.owner_id satisfies only incidents table but not users).if the condition satisfies both tables only we can able to display fields from both tables.. Quote Link to comment Share on other sites More sharing options...
zenag Posted April 30, 2008 Share Posted April 30, 2008 yeah...just noew i ve came to my seat.....right now hve seen ur mail.....i wl check it out... Quote Link to comment Share on other sites More sharing options...
zenag Posted April 30, 2008 Share Posted April 30, 2008 sorry pal....ur query works fine ..ur correct...set in ur database for owner_id field as default value as NULL OR 0 in mysql...it will work fine.. $result3 = mysql_query("SELECT users.firstname,incidents.description,users.surname,incidents.owner_id FROM incidents,users where (incidents.owner_id = users.id) OR (incidents.owner_id < '$uuid') OR (incidents.owner_id = NULL)",$link); Quote Link to comment Share on other sites More sharing options...
tuxbuddy Posted April 30, 2008 Author Share Posted April 30, 2008 What incidents.owner_id < '$uuid' means?? Quote Link to comment Share on other sites More sharing options...
zenag Posted April 30, 2008 Share Posted April 30, 2008 while ($row1=mysql_fetch_row($result2)){ $uuid=$row1[0]; echo $uuid; } [quote] i ve assigned this value...echo $uuid; [/quote] #$result3 = mysql_query("SELECT users.firstname,users.surname,incidents.owner_id FROM incidents,users where (incidents.owner_id = users.id) OR (incidents.owner_id = NULL) $result3 = mysql_query("SELECT users.firstname,incidents.description,users.surname,incidents.owner_id FROM incidents,users where (incidents.owner_id = users.id) OR (incidents.owner_id < '$uuid') AND (incidents.owner_id = 0)",$link); refer this.... this query might help u ...check this query ..it will output results from users table where owner_id in incidents table is null... SELECT users.firstname,incidents.description,users.surname,incidents.owner_id FROM users LEFT OUTER JOIN incidents ON incidents.owner_id = users.id WHERE incidents.owner_id IS NULL Quote Link to comment Share on other sites More sharing options...
zenag Posted April 30, 2008 Share Posted April 30, 2008 OUT FOR LUNCH BE BACK AT 2.PM Quote Link to comment Share on other sites More sharing options...
tuxbuddy Posted April 30, 2008 Author Share Posted April 30, 2008 Th query displays: SQL-query: SELECT users.firstname, incidents.description, users.surname, incidents.owner_id FROM users LEFT OUTER JOIN incidents ON incidents.owner_id = users.id WHERE incidents.owner_id IS NULL LIMIT 0 , 30 [Edit] [Explain SQL] [Create PHP Code] [Refresh] row(s) starting from record # in horizontal horizontal (rotated headers) vertical mode and repeat headers after cells firstname description surname owner_id Prasanth NULL M NULL Sijo NULL Jose NULL Ram NULL Prasad NULL Josin NULL Jose NULL Prabhu NULL Hosmani NULL jose NULL NULL vinod NULL prasad NULL venkat NULL NULL NULL Ajit NULL Raina NULL Samreen NULL Raina NULL priya NULL priya NULL Sumit NULL sumit NULL vidya NULL NULL row(s) starting from record # in horizontal horizontal (rotated headers) vertical mode and repeat Whats that for? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.