Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6223407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:29:02+00:00 2026-05-24T08:29:02+00:00

I have a php script that outputs a link element within a list element

  • 0

I have a php script that outputs a link element within a list element depending on certain conditions being met, the code is as follows:

    global $wpdb;

    function currentURL() {

        $pageURL = 'http';
        if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
        $pageURL .= "://";
        if ($_SERVER["SERVER_PORT"] != "80") {
            $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
        } else {
            $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
        }
        return $pageURL;}

    $getUrl = $wpdb->get_results("SELECT option_name,option_value FROM wp_options WHERE option_name = 'siteurl' ");

    $url = $geturl->option_value;

    $getData = $wpdb->get_results("SELECT post_title,guid FROM wp_posts WHERE post_type = 'page' ");

    echo "<ul id=\"mainNavInnerContainer\">"; 

    if(currentURL() == $url){
    echo "<li><a href=\"" . $url . "\" id=\"current\">home</a></li>";}

    else{ echo "<li><a href=\"" . $url . "\">home</a></li>"; }

The problem I’m having is that when I view the element in source code view in my browser i get the following:

<a href>Home</a>

I’m really confused as to why this is, and was hoping that anyone else would have any idea why.

EDIT
I was able to use a foreach loop to put the value in my $url variable but is this good practice? Because I know that the query in $getUrl will always return one row, but still this method seems pretty error prone. Here is the revised $url variable code:

        foreach($getUrl as $urlResult){
        $url = $urlResult->option_value;}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:29:02+00:00Added an answer on May 24, 2026 at 8:29 am
    1. add to top of code error_reporting(E_ALL);
    2. add check:

      $getUrl = $wpdb->get_results("SELECT option_name,option_value FROM wp_options WHERE option_name = 'siteurl' ");    
          $url = $geturl->option_value;
      var_dump($url);
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Specifically I have a PHP command-line script that at a certain point requires input
I have a PHP script hosted on my site that outputs a value based
I have a PHP script (running on a Linux server) that ouputs the names
I have a PHP script that runs as a CGI program and the HTTP
I have a PHP script that needs to determine if it's been executed via
I have a PHP script that initialises an image gallery. It loops through all
I have a PHP script that can encode a PNG image to a Base64
I have a PHP script that sends critical e-mails. I know how to check
I have a PHP script that processes file uploads. The script tries to organise
I have a PHP script that pushes the headers to allow a file to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.