0

我有几个 php 页面,用于在数据库中搜索我在管理面板中创建的促销代码

我正在努力将这些代码回显到促销页面

我的广告很简单

广告.php

<body>
    <div>
        <!-- Start SPECIAL OFFER/PROMO -->
        <div id="specialPromo" class="specialPromo">
            <p class="promoTitle">promotion title!</p>
            <p class="promoText">here is our promotion code</p>
        <div class="promoCodeBox">
            <!-- PROMO CODE -->
            <p class="promoCode"><?echo $showcode?></p>
            <!-- PROMO CODE -->
        </div>
        <div class="promoBtn"><a class="cupid-green" href="index.php?action=signup">JOIN NOW</div></a></div>
        <!-- End SPECIAL OFFER/PROMO -->
    </div>

</body>
</html> 

然后链接到另一个页面

获取代码.php

<? 
include ("include/universal.php");


//execute the SQL query and return records
$result = mysql_query("SELECT  discount_code FROM discount_codes WHERE discount_name='".$code."'"); 
 //fetch tha data from the database
while ($row = mysql_fetch_array($result)) 
{
$showcode = ($row{'discount_code'});
}

//close the connection
mysql_close($condb);

?>

问题在于这段代码

$code = $code["code1"];

如果我将它放在 getcodes.php 中,则可以正常工作并获得结果

但我想把它放在 advert.php

最终计划是创建一个管理页面,我可以在其中选择一个广告并输入代号,它将自动填充要在该广告中使用的代码

但我什至无法让它与单个广告一起使用,直到我发现我没有机会从单个页面管理多个添加

任何关于我哪里出错的建议,请记住我现在只使用 php 2 周

提前谢谢大家的建议

4

1 回答 1

0

经过大量阅读后,我想通了,这很简单,所以不知道为什么没有人能提供帮助,也许是精英主义,我发现在其他网站中

这里的任何方式都是我解决它的方法

我将我的 getcodes.php 更改为:

<? 

include ("universal.php");

//CREATE AN ARRAY FOR OUT PUT
$showcode = array();
$showname = array();

//execute the SQL query and return records
$result = mysql_query("SELECT discount_name, discount_code FROM discount_codes"); 
//fetch tha data from the database
while ($row = mysql_fetch_array($result)) 
{
// create rusults for posting
$showcode[] = $row{'discount_code'};
$showname[] = $row{'discount_name'};

/* post results*/
//echo $showcode[]; //(copy to destination)
//echo $showname[];  //(copy to destination) 
}

//close the connection
mysql_close($condb);

?>

重要的是

//CREATE AN ARRAY FOR OUT PUT
$showcode = array();
$showname = array();

// create rusults for posting
$showcode[] = $row{'discount_code'};
$showname[] = $row{'discount_name'};

这让我可以使用

/* post results*/
//echo $showcode[?]; //(copy to destination)
//echo $showname[?];  //(copy to destination)

只需在我想输出结果的地方使用以下内容

echo $showcode[?];
echo $showname[?];

明显地 ?whoud 更改为代表当前提供的折扣代码的数字

使用此选项使我无需将广告页面中的任何内容发布到搜索中以提取所需代码,这只需将它们全部拉出,然后允许我选择要回显的内容

于 2013-03-06T12:53:43.743 回答