如何在超链接中显示

如何在超链接中显示

本文介绍了如何在超链接中显示 PHP 变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试回显一个变量,以便它显示在我的超链接中.这是我当前的代码:

I'm trying to echo a variable so it shows in my hyperlink. Here's my current code:

<?php

if (!defined("WHMCS"))
        die("This file cannot be accessed directly");


$customerserviceid = mysql_query("SELECT id FROM `tblhosting` WHERE `userid` = '{$_SESSION['uid']}'");

function limitOrders($vars) {
        if(mysql_num_rows(mysql_query("SELECT packageid FROM `tblhosting` WHERE `userid` = '{$_SESSION['uid']}'")) > 0) {

                if($packageid = '1' || $packageid = '2' || $packageid = '3' || $packageid = '4' || $packageid = '5' || $packageid = '6' || $packageid = '7' || $packageid = '8' || $packageid = '9' || $packageid = '10') {
                global $errormessage;
                $errormessage = "<li>It looks like you already have an account!  Please <a href='http://mywebsite.com/upgrade.php?type=package&id=$customerserviceid'>click here</a> to upgrade or downgrade your account.</li>";
                }
        }
}
add_hook("ShoppingCartValidateCheckout", 1, "limitOrders");
?>

我尝试将 $customerserviceid 添加到第 14 行的 URL 中,但它只显示空白,所以我猜我没有正确添加某些内容.当我在 phpMyAdmin 中运行查询时,它确实显示了我想要的内容,因此查询本身应该是正确的...

I tried adding $customerserviceid into the URL on line 14 but it just shows blank so I'm guessing that I didn't add something correctly. When I run the query in phpMyAdmin it does show what I'm wanting so the query itself should be correct...

推荐答案

需要从查询结果中取出结果,然后使用global访问全局变量.

You need to fetch the results from the query results, and then use global to access the global variable.

<?php
if (!defined("WHMCS"))
        die("This file cannot be accessed directly");

$result = mysql_query("SELECT id FROM `tblhosting` WHERE `userid` = '{$_SESSION['uid']}'");
$row = mysql_fetch_assoc($result);
$customerserviceid = $row['id'];

function limitOrders($vars) {
    global $customerserviceid;
    if(mysql_num_rows(mysql_query("SELECT packageid FROM `tblhosting` WHERE `userid` = '{$_SESSION['uid']}'")) > 0) {

        if($packageid = '1' || $packageid = '2' || $packageid = '3' || $packageid = '4' || $packageid = '5' || $packageid = '6' || $packageid = '7' || $packageid = '8' || $packageid = '9' || $packageid = '10') {
        global $errormessage;
        $errormessage = "<li>It looks like you already have an account!  Please <a href='http://mywebsite.com/upgrade.php?type=package&id=$customerserviceid'>click here</a> to upgrade or downgrade your account.</li>";
        }
    }
}
add_hook("ShoppingCartValidateCheckout", 1, "limitOrders");
?>

这篇关于如何在超链接中显示 PHP 变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 22:33