Jump to content

Recommended Posts

I'm having problems populating my array... logically the code seems fine to me, any ideas?

 

            $query = mysql_query("SELECT ALU_7705_Statuses.StatusID, ALU_7705_Statuses.SiteID, Sites.SiteName FROM ALU_7705_Statuses LEFT JOIN Sites ON ALU_7705_Statuses.SiteID = Sites.SiteID WHERE ALU_7705_Statuses.Market = '$_SESSION[AllowedMarket]' AND ALU_7705_Statuses.CompleteIncomplete = 'Incomplete'", $a_link);
            $resultcount = mysql_num_rows($query);
            while ($row = mysql_fetch_assoc($query)) {
                $StatusID = "";
                $SiteName = "";
                $DateTimeOfStatus = "";
                $Status = "";
                $Statusor = "";
                $Notes = "";
                $subquery = mysql_query("SELECT Status_Reports.TechID, Status_Reports.DateTimeOfStatus, Status_Reports.Status, Status_Reports.Notes, Users.FirstName, Users.LastName FROM Status_Reports LEFT JOIN Users ON Status_Reports.TechID = Users.UserID WHERE Status_Reports.StatusID = '$row[statusID]' ORDER BY StatusReportID DESC LIMIT 1", $a_link);
                while ($subrow = mysql_fetch_assoc($subquery)) {
                    $StatusID = $row['StatusID'];
                    $SiteName = $row['SiteName'];
                    $DateTimeOfStatus = $subrow['DateTimeOfStatus'];
                    $Status = $subrow['Status'];
                    $Statusor = $subrow['FirstName'].' '.$subrow['LastName'];
                    $Notes = $subrow['Notes'];
                    echo '
            <tr><td><a href="sitestatrep.php?StatusID='.$row["StatusID"].'">'.$row["SiteID"].'</a></td>
                    <td>'.$row["SiteName"].'</td>
                    <td>'.date("M j, Y g:i a", strtotime($subrow["DateTimeOfStatus"])).'</td>
                    <td>'.$subrow["Status"].'</td>
                    <td>'.$subrow["FirstName"].' '.$subrow["LastName"].'</td>
                    <td>'.substr($subrow["Notes"], 0, 22).' ';if($subrow['Notes'] != ""){echo'...';}echo '</td>
            </tr>';
                }
                for ($i=0;$i<$resultcount;$i++) {
                    $resultsarray[$i]["StatusID"] = $StatusID;
                    $resultsarray[$i]["SiteName"] = $SiteName;
                    $resultsarray[$i]["DateTimeOfStatus"] = $DateTimeOfStatus;
                    $resultsarray[$i]["Status"] = $Status;
                    $resultsarray[$i]["Statusor"] = $Statusor;
                    $resultsarray[$i]["Notes"] = $Notes;
                }
            }

 

But when I print_r it, it filled all of the values with the last row of data...

Link to comment
https://forums.phpfreaks.com/topic/228950-an-array-issue/
Share on other sites

try

$i = 0;
$query = mysql_query("SELECT ALU_7705_Statuses.StatusID, ALU_7705_Statuses.SiteID, Sites.SiteName FROM ALU_7705_Statuses LEFT JOIN Sites ON ALU_7705_Statuses.SiteID = Sites.SiteID WHERE ALU_7705_Statuses.Market = '$_SESSION[AllowedMarket]' AND ALU_7705_Statuses.CompleteIncomplete = 'Incomplete'", $a_link);
            $resultcount = mysql_num_rows($query);
            while ($row = mysql_fetch_assoc($query)) {
                $StatusID = "";
                $SiteName = "";
                $DateTimeOfStatus = "";
                $Status = "";
                $Statusor = "";
                $Notes = "";
                $subquery = mysql_query("SELECT Status_Reports.TechID, Status_Reports.DateTimeOfStatus, Status_Reports.Status, Status_Reports.Notes, Users.FirstName, Users.LastName FROM Status_Reports LEFT JOIN Users ON Status_Reports.TechID = Users.UserID WHERE Status_Reports.StatusID = '$row[statusID]' ORDER BY StatusReportID DESC LIMIT 1", $a_link);
                while ($subrow = mysql_fetch_assoc($subquery)) {
                    $StatusID = $row['StatusID'];
                    $SiteName = $row['SiteName'];
                    $DateTimeOfStatus = $subrow['DateTimeOfStatus'];
                    $Status = $subrow['Status'];
                    $Statusor = $subrow['FirstName'].' '.$subrow['LastName'];
                    $Notes = $subrow['Notes'];
                    echo '
            <tr><td><a href="sitestatrep.php?StatusID='.$row["StatusID"].'">'.$row["SiteID"].'</a></td>
                    <td>'.$row["SiteName"].'</td>
                    <td>'.date("M j, Y g:i a", strtotime($subrow["DateTimeOfStatus"])).'</td>
                    <td>'.$subrow["Status"].'</td>
                    <td>'.$subrow["FirstName"].' '.$subrow["LastName"].'</td>
                    <td>'.substr($subrow["Notes"], 0, 22).' ';if($subrow['Notes'] != ""){echo'...';}echo '</td>
            </tr>';

                    $resultsarray[$i]["StatusID"] = $StatusID;
                    $resultsarray[$i]["SiteName"] = $SiteName;
                    $resultsarray[$i]["DateTimeOfStatus"] = $DateTimeOfStatus;
                    $resultsarray[$i]["Status"] = $Status;
                    $resultsarray[$i]["Statusor"] = $Statusor;
                    $resultsarray[$i]["Notes"] = $Notes;
                    $i++
                }
            }

Link to comment
https://forums.phpfreaks.com/topic/228950-an-array-issue/#findComment-1180102
Share on other sites

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.