skip to Main Content

My index.php page has a display of listings from a json file which looks good. But I am trying to send a result of a single listing from that page to another page (result.php). How do I display the results of that single listing to the new page?

Here is the code for my first page that is attached to the json file:

<?php
$filename = file_get_contents("/ListingCollection.json");
$listings = json_decode($filename);
?>

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
    <script src="https://kit.fontawesome.com/ac048d9955.js" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
    
<body>
<div style="margin-left:150px; margin-right:150px; margin-bottom:150px;">
<?php foreach ($listings as $listing) { ?>
 <span style="visibility:hidden;"><?= $listing->Oid; ?></span>
    <div class="row align-items-center border-top">
        <div class="col-3" style="padding:10px;">
            <?= $listing->AdPhoto; ?>
        </div>
        <div class="row col-8" style="margin-left:10px;">
            <div class="col-8 align-items-center">
                <h2 style="color:#00471C; width: 700px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" type="button"><?= $listing->AdTitle; ?></h2>
                <h3><?= $listing->AdTagLine; ?></h3>
                <p><?= $listing->AdTagLine; ?></p>
            </div>
            <div class="col-4 align-items-start">
                <center><h1><?= $listing->ListingPrice; ?></h1><h3>EBITDA: $<?= $listing->EBITDA; ?></h3></center><br><br>
                <center><a class="btn btn-primary" href="<?= $listing->WebsiteURL; ?>?<?= $listing->Oid; ?>" role="button">See Listing</a></center>
            </div>
        </div>
    </div>
<?php  } ?>
</div>
</body>
</html>

Here is the code to my second page that I want to pull from single listing of index.php file:

<?php
require($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
get_header();  
$filename = file_get_contents("/ListingCollection.json");
$listings = json_decode($filename);
?>

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
    <script src="https://kit.fontawesome.com/ac048d9955.js" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>

<body>
<div style="margin-left:150px; margin-right:150px; margin-top:50px; margin-bottom:50px;">
 <?php foreach ($listings as $listing) { ?>
<!-- Ad Header -->
    <div class="row align-items-center" style="margin-bottom:25px;">
        <div class="col-12">
            <h1><?= $listing->AdTitle; ?></h1>
            <h3><?= $listing->County; ?>, <?= $listing->State; ?></h3>
        </div>
    </div>
<!-- Ad Photo -->
    <div class="row" style="margin-bottom:25px;">
        <div class="row col-8 align-items-center">
            <div class="col-12">
                <?= print "Your registration is: ".$regValue."."; ?>
                <?= $listing->AdPhoto; ?><br><br>
            </div>
<!-- Ad Pricing -->
            <div class="col-6">
                <h2>ASKING PRICE: $<?= $listing->ListingPrice; ?></h2>
            </div>
            <div class="col-6">
                <h2>CASH FLOW: $<?= $listing->CashFlow; ?></h2>
            </div>
<!-- Above button info -->
                <div class="col-3">Gross Revenue: </div><div class="col-3">$<?= $listing->GrossRevenue; ?> </div><div class="col-3">Inventory: </div><div class="col-3">$<?= $listing->Inventory; ?></div>
                <div class="col-3">EBITDA: </div><div class="col-3">$<?= $listing->EBITDA; ?> </div><div class="col-3">Rent: </div><div class="col-3">$<?= $listing->Rent; ?> </div>
                <div class="col-3">FF&E: </div><div class="col-3">$<?= $listing->FFandE; ?> </div><div class="col-3">Established: </div><div class="col-3"><?= $listing->YearEstablished; ?> </div><br><br>
<!-- buttons -->
            <div class="col-3">
                <a class="btn btn-primary" style="width:100%;" type="button" href="">SAVE</a>
            </div>
            <div class="col-3">
                <a class="btn btn-primary" style="width:100%;" type="button" href="">PRINT</a>
            </div>
            <div class="col-3">
                <a class="btn btn-primary" style="width:100%;" type="button" href="">SHARE</a>
            </div>
            <div class="col-3">
                <a class="btn btn-primary" style="width:100%;" type="button" href="">VALUATION REPORT</a>
            </div>
<!-- Ad Description -->
            <div class="col-12"><br><br><hr><br>
                <h2>DESCRIPTION</h2>
                <h2><?= $listing->AdTagLine; ?></h2>
                <?= $listing->AdDescription ?><br>
                <hr><br>
            </div>
<!-- Ad Details -->
            <div class="col-3">
                <h3>Location:</h3>
            </div>
            <div class="col-9">
                <?= $listing->County ?> 
            </div>
            <div class="col-3">
                <h3>Building SF:</h3>
            </div>
            <div class="col-9">
                <?= $listing->TotalSqFt ?> 
            </div>
            <div class="col-3">
                <h3>Employees:</h3>
            </div>
            <div class="col-9">
                <?= $listing->EmployeeCount ?> 
            </div>
            <div class="col-3">
                <h3>Facilities:</h3>
            </div>
            <div class="col-9">
                <?= $listing->AdFacilityDescription ?> 
            </div>
            <div class="col-3">
                <h3>Competition:</h3>
            </div>
            <div class="col-9">
                <?= $listing->AdCompetitiveAnalysis ?> 
            </div>
            <div class="col-3">
                <h3>Growth & Expansion:</h3>
            </div>
            <div class="col-9">
                <?= $listing->AdOpportunityForGrowth ?> 
            </div>
            <div class="col-3">
                <h3>Support & Training:</h3>
            </div>
            <div class="col-9">
                <?= $listing->AdSupportAndTraining ?> 
            </div>
            <div class="col-3">
                <h3>Reason for Selling:</h3>
            </div>
            <div class="col-9">
                <?= $listing->AdReasonForSelling ?> 
            </div>
            <div class="col-3">
                <h3>Business Website:</h3>
            </div>
            <div class="col-9">
                <?= $listing->WebsiteURL ?> 
            </div>
        </div>
        <div class="col-4 bg-light">
            <div class="container">
  <!-- CHANGE THE URL HERE -->
                <div class="col-12">
                    <form action="https://app.99inbound.com/e/123" method="POST" target="_blank">
                        <h1 style="text-align: center;"><br>CONTACT US</h1>
                    <div class="form-group">
                        <input name="name" type="text" class="form-control" id="name" placeholder="Full Name" required>
                        <input name="phone" type="phone" class="form-control" id="phone" placeholder="Phone Number" required>
                        <input name="email" type="email"  class="form-control" id="email" placeholder="Enter Email" required>
                    </div>
                    <div class="form-group">
                        <textarea name="message" class="form-control" id="message" rows="5" placeholder="Enter message" required></textarea>
                    </div>
                    <button type="submit" class="btn btn-primary">Submit</button>
                    </form>
                    <br><hr>
                </div>
                <div class="row col-12">
                    <div class="col-6"><p>Business Listed By:<br>
                    <?= $listing->SellerFirstName; ?> <?= $listing->SellerLastName; ?></p></div>
                    <div class="col-6"><p><i class="fas fa-phone-square-alt"></i> <?= $listing->SellerPhone; ?></div>
                </div>
            </div>
        </div>
    </div>
<?php  } ?>
</div>
<?php get_footer(); ?>
</body>
</html>

2

Answers


  1. Chosen as BEST ANSWER

    I fixed the problem by doing this to the button:

    <?php echo"<a class='btn btn-primary' role='button' href='https://samplesite.com/result.php?" . http_build_query($listing) . "'>See Listing</a>"; ?>

    Then echoing the items on the results page.


  2. I might make a subtle change to the link to turn the ?id into a key/value pair, like

    <center><a class="btn btn-primary" href="<?= $listing->WebsiteURL; ?>?display=<?= $listing->Oid; ?>" role="button">See Listing</a></center>
    

    Then on the second page

    <?php
    require($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
    get_header();  
    $filename = file_get_contents("/ListingCollection.json");
    $display = $_GET['display'];
    $listings = json_decode($filename);
    $listing=array_filter($listings, function($a) use($display) {
        return $a->Oid === $display;
     });
    $listing = array_values($listing)[0];
    
    
    // get rid of the loop on this page
    //  foreach ($listings as $listing) {  <-- GONE
    
    ?>
    
    <!-- then the rest of your code, using $listing -->
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search