CodeMama Posted March 3, 2009 Share Posted March 3, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/147751-display-issues-not-displaying-all-records/ Share on other sites More sharing options...
a-scripts.com Posted March 3, 2009 Share Posted March 3, 2009 $row = mysql_fetch_assoc($result); this actually sets $row to current row from result set .. you want to iterate through all rows with something like while( $row = mysql_fetch_assoc($result) ) { echo $row['UserName']; } Quote Link to comment https://forums.phpfreaks.com/topic/147751-display-issues-not-displaying-all-records/#findComment-775585 Share on other sites More sharing options...
HuggieBear Posted March 3, 2009 Share Posted March 3, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/147751-display-issues-not-displaying-all-records/#findComment-775588 Share on other sites More sharing options...
CodeMama Posted March 3, 2009 Author Share Posted March 3, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/147751-display-issues-not-displaying-all-records/#findComment-775634 Share on other sites More sharing options...
CodeMama Posted March 3, 2009 Author Share Posted March 3, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/147751-display-issues-not-displaying-all-records/#findComment-775780 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.