Jump to content

Recommended Posts

I have two queries one pulls out which users to use and the second pulls those users orders....

Looks something like this but is only pulling the first record:

 

 

    $query =  "SELECT `UserName`, `AdminID` FROM admin

      WHERE  Key1 =  'YES' ";

 

    $result = mysql_query ($query) ;   

    $row = mysql_fetch_assoc($result);

   

    //Reveal Variables for Debugging

    // include("VariableReveal2.php");

      echo ("Hello <br>");

    //echo $row['AdminID'];

    echo ($row['UserName']);

   

 

       

 

    if ($row['Key1'] == "NO") {

        header ("Location: Welcome.php?AdminID=$AdminID&msg=Sorry, you do not have access to that page.");

    }

   

if (isset($_GET['SortBy'])) {$SortBy = $_GET['SortBy'];} else {$SortBy = 'WorkOrderID DESC';}

if (isset($_GET['Page'])) {$Page = $_GET['Page'];} else {$Page = 1;}

 

$PerPage = 30;

$StartPage = ($Page - 1) * $PerPage;

 

        second query here is using the $row from the first (and yes I know not to use *, just did so here to keep post shorter)

 

        $sql= "SELECT * FROM workorders WHERE AdminID =  '".$row['AdminID']."' ";

      // $sql .= "ORDER BY $SortBy LIMIT $StartPage, $PerPage";

      $result = mysql_query ($sql);

      $row2 = mysql_fetch_assoc($result);

      $Total = ceil(mysql_num_rows($result)/$PerPage);

   

 

    So this works but only half way as it only displays the first record in the table.

 

 

 

Thanks

Terion

 

if ($row['Key1'] == "NO") {
   header ("Location: Welcome.php?AdminID=$AdminID&msg=Sorry, you do not have access to that page.");
}

 

BTW. The above code will never be invoked as your initial query only returns rows where Key1 = 'YES'.

 

Edit: In fact, $row['Key1'] is never even set as it's not in the columns requested.

Well I got the first query to return all the records correctly

    $query =  "SELECT `UserName`, `AdminID` FROM admin
      WHERE   Retail1 =  'YES' ";
  
    $result = mysql_query ($query) ;	
    //$row = mysql_fetch_array($result);
while ($row = mysql_fetch_row($result)){
for ($i=0; $i<mysql_num_fields($result); $i++)
	echo $row[$i] . " ";
	//print a return for neatness sake
	echo "\n";
	}
//Reveal Variables for Debugging
     //include("VariableReveal2.php");
 echo ("Hello <br>");
    //echo $row['AdminID'];
echo ("$row <br>");

but the second query still does not work, in fact now it works less as it returns O records not even the first one...

I tried using the about type format but it didn't work perhaps its the way i"m trying to use the $row in the WHERE?

         $sql= "SELECT * FROM workorders WHERE AdminID =   '".$row['AdminID']."' ";
   $sql .= "ORDER BY $SortBy LIMIT $StartPage, $PerPage";
      $result = mysql_query ($sql);
  $row2 = mysql_fetch_assoc($result);

  $Total = ceil(mysql_num_rows($result)/$PerPage);


     

  

So my second part looks like this and it isn't breaking and is trying to return records but it isn't getting any of the AdminID's from the first query so this part must be wrong

   $sql= "SELECT WorkOrderID, CreatedDate, Location, WorkOrderName, AdminID, FormName, Status, Notes, pod FROM `workorders` WHERE AdminID = '".$row['AdminID']."' "; 

 

Pretty sure the red part is what is wrong but how to fix it...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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