1

I am building my first angular app and I have almost finished it but I have one page left to complete that is causing me a bit of a headache.

So I have a page that lists trips I have been on. This is done with the following code.

<?php
 $sql = "SELECT * FROM tripreport WHERE userid = $userid LIMIT 10";
            $result = $conn->query($sql);

            if ($result->num_rows > 0) {
              while($row = $result->fetch_assoc()) {
      ?>
<div class="row">
   <div class="col-lg-7 col-md-7">
        <a href="#">
            <img class="img-responsive" src="reportimages/<?php echo $row['banner_img'];?>" alt="">
        </a>
    </div>
    <div class="col-lg-5 col-md-5">
        <h3><?php echo $row['reportname'];?></h3>
        <h4><?php echo $row['reportstartdate'];?>
            <strong class="pull-right "><?php echo $row['likes'];?> Likes</strong>
        </h4>
        <hr class="border-gray">
        <?php echo $row['reportdescription'];?>
        <hr class="border-gray">
        <a class="btn bg-green" href="#!/report-listing"></span>Manage</a>
        </div>
    </div>
</div>

So my URL is the below:

<a class="btn bg-green" href="#!/report-listing"></span>Manage</a>

I need this to get the ID from the database and have this posted to the report listing page so I can pull out corresponding reports.

I assume something needs to go in to my angular-menu.js JS to do this which currently only has:

         when('/report-listing', {
        templateUrl: 'pages/report-listing.php',
        controller: ReportListingsCtrl,
        activetab: 'report-listing'
    }).

Also I think I will need something in my controller.js file which I currently have set as:

function ReportListingsCtrl($scope, $http, $timeout) {}

Any help would be appreciated.

1 Answer 1

1

Firstly, tell your destination controller (the page you are referring to) to expect and accept a parameter when we navigate to that page.In your app.js, introduce :reportId param to send the id.

$routeProvider.when('/report-listing/:reportId?', {
            templateUrl: 'pages/report-listing.php',
            controller: ReportListingsCtrl,
            activetab: 'report-listing'
        }).

The question mark after the parameter denotes that it's an optional parameter.

<a class="btn bg-green" href="#!/report-listing/3"></span>Manage</a>

And in the Controller.js, you access the id as such.

function ReportListingsCtrl($scope, $http, $timeout,$routeParams) {
$scope.id=$routeParams.reportId;
}
Sign up to request clarification or add additional context in comments.

4 Comments

So now, if you wouldn't mind what is the method to pull the ID out on the next page so I can get the ID in to my sql statement to pull out the data?
i don't quite understand what you are saying, however, are you perhaps referring to pass the data from one controller to another?
So now I am on #!/ report-listing/3 page, I want to ge the 3 from the URL so I can use it in my mySQL statement to use in my PHP to get the right data
why don't you send the id to the api that is in php? through angular http post or ajax or any that you find easier

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.