Jump to content

PHP+MySQL??


tuxbuddy

Recommended Posts

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



Link to comment
Share on other sites

  • Replies 75
  • Created
  • Last Reply

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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";
}
}

?>

                     

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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";
}
}

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.