javascript——我有一个业务销售页面,显示json文件的结果我希望能够在结果页面上传递一个列表的信息

w1jd8yoj  于 2021-09-13  发布在  Java
关注(0)|答案(2)|浏览(169)

my index.php页面显示了一个json文件中的列表,看起来不错。但是我正在尝试将一个列表的结果从该页面发送到另一个页面(result.php)。如何将单个列表的结果显示到新页面?
以下是附加到json文件的我的第一页的代码:

<?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/bootstrap@4.6.0/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/bootstrap@4.6.0/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>

下面是我想从index.php文件的单个列表中提取的第二个页面的代码:

<?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/bootstrap@4.6.0/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/bootstrap@4.6.0/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>
s3fp2yjn

s3fp2yjn1#

我可能会对链接做一个细微的更改以打开 ?id 进入一个键/值对,如

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

然后在第二页

<?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 -->
yjghlzjz

yjghlzjz2#

我通过对按钮执行以下操作修复了问题:

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

然后回显结果页面上的项目。

相关问题