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

  • SEARCH
  • Home
  • 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 9200173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:42:23+00:00 2026-06-17T22:42:23+00:00

The MySQL selects are not displaying properly in the PHP / HTML This is

  • 0

The MySQL selects are not displaying properly in the PHP / HTML

This is my code:

<?php
session_start();
require_once("database.php");
require_once("MySQL_connection.php");

/* Database connection */
$db = new MySQLConnection($config['sql_host'], $config['sql_username'], $config['sql_password'], $config['sql_database']);
$db->Connect();

unset($config['sql_password']);

/* Cron */
require_once("cron.php");

/* Display Advert */

$ad_link = $db->Query("SELECT `site_url` FROM `adverts` WHERE `zone`=1 AND `days`>0 ORDER BY RAND() LIMIT 0,1;");

$img_link = $db->Query("SELECT `image_url` FROM `adverts` WHERE `zone`=1 AND `days`>0 ORDER BY RAND() LIMIT 0,1;");

?>

<!DOCTYPE html>
<html>
<body>
<a href="<?php echo $ad_link ?>"><img src="<? echo $img_link ?>"></a>
</body>
</html>

For some reason that is displaying as:

<html><head></head><body>
<a href="Resource id #6"><img src="Resource id #7"></a>

</body></html>

Is anybody know what is wrong?

Forgot to add the code for MYSQL_connection.php, the following code is everything within that file that is used to connect to the DB.

<?php


class MySQLConnection {

    private $sqlHost;
    private $sqlUser;
    private $sqlPassword;
    private $sqlDatabase;

    private $mySqlLinkIdentifier = FALSE;

    public $QueryFetchArrayTemp = array();

    private $numQueries = 0;

    public $UsedTime = 0;

    public function __construct($sqlHost, $sqlUser, $sqlPassword, $sqlDatabase = FALSE) {
        $this->sqlHost = $sqlHost;
        $this->sqlUser = $sqlUser;
        $this->sqlPassword = $sqlPassword;
        $this->sqlDatabase = $sqlDatabase;
    }

    public function __destruct() {
        $this->Close();
    }

    public function Connect() {
        if($this->mySqlLinkIdentifier !== FALSE) {
            return $this->mySqlLinkIdentifier;
        }

        $this->mySqlLinkIdentifier = mysql_connect($this->sqlHost, $this->sqlUser, $this->sqlPassword, TRUE); // Open new link on every call
        if($this->mySqlLinkIdentifier === FALSE) {
            return FALSE;
        }

        if($this->sqlDatabase !== FALSE) {
            mysql_select_db($this->sqlDatabase, $this->mySqlLinkIdentifier);
        }

        return $this->mySqlLinkIdentifier;
    }

    public function Close() {
        if($this->mySqlLinkIdentifier !== FALSE) {
            mysql_close($this->mySqlLinkIdentifier);
            $this->mySqlLinkIdentifier = FALSE;
        }
    }

    public function GetLinkIdentifier() {
        return $this->mySqlLinkIdentifier;
    }       

    public function Query($query) {
        $start = microtime(true);
        $result = mysql_query($query, $this->GetLinkIdentifier());
        $this->UsedTime += microtime(true) - $start;
        $this->numQueries++;

        if( $result === false ){
            die($this->GetErrorMessage());
        }

        return $result;
    }

    public function FreeResult($result) {
        mysql_free_result($result);
    }

    public function FetchArray($result) {
        return mysql_fetch_array($result, MYSQL_ASSOC);
    }

    public function FetchArrayAll($result){
        $retval = array();
        if($this->GetNumRows($result)) {
            while($row = $this->FetchArray($result)) {
                $retval[] = $row;
            }           
        }
        return $retval;
    }   

    public function GetNumRows($result) {
        return mysql_num_rows($result);
    }

    public function GetNumAffectedRows() {
        return mysql_affected_rows($this->mySqlLinkIdentifier);
    }


    // Helper methods
    public function QueryFetchArrayAll($query) {
        $result = $this->Query($query);
        if($result === FALSE) {
            return FALSE;
        }

        $retval = $this->FetchArrayAll($result);
        $this->FreeResult($result);

        return $retval;         
    }

    public function QueryFirstRow($query) {
        $result = $this->Query($query);
        if($result === FALSE) {
            return FALSE;
        }

        $retval = FALSE;

        $row = $this->FetchArray($result);
        if($row !== FALSE) {
            $retval = $row;
        }

        $this->FreeResult($result);

        return $retval;     
    }

    public function QueryFirstValue($query) {
        $row = $this->QueryFirstRow($query);
        if($row === FALSE) {
            return FALSE;
        }

        return $row[0];         
    }

    public function GetErrorMessage() {
        return "SQL Error: ".mysql_error().": ";
    }

    public function EscapeString($string) {
        if (is_array($string))
        {
            $str = array();
            foreach ($string as $key => $value)
            {
                $str[$key] = $this->EscapeString($value);
            }

            return $str;
        }

        return get_magic_quotes_gpc() ? $string : mysql_real_escape_string($string, $this->mySqlLinkIdentifier);
    }

    function GetNumberOfQueries() {
        return $this->numQueries;
    }

    public function BeginTransaction() {
        $this->Query("SET AUTOCOMMIT=0");
        $this->Query("BEGIN");
    }

    public function CommitTransaction() {
        $this->Query("COMMIT");
        $this->Query("SET AUTOCOMMIT=1");
    }

    public function RollbackTransaction() {
        $this->Query("ROLLBACK");
        $this->Query("SET AUTOCOMMIT=1");
    }

    public function GetFoundRows() {
        return $this->QueryFirstValue("SELECT FOUND_ROWS()");
    }

    public function GetLastInsertId() {
        return $this->QueryFirstValue("SELECT LAST_INSERT_ID()");           
    }


    public function QueryFetchArray($query, $all = false, $useCache = true)
    {
        $tempKey = sha1($query . ($all === true ? 'all' : 'notAll'));
        $temp = $this->QueryFetchArrayTemp[$tempKey];

        if ($temp && $useCache === true)
        {
            return unserialize($temp);
        }
        else
        {
            $queryResult = $this->Query($query);
            $result = $all === true ? $this->FetchArrayAll($queryResult) : $this->FetchArray($queryResult);

            $this->QueryFetchArrayTemp[$tempKey] = serialize($result);
            return $result;
        }
    }
}
?>
  • 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-06-17T22:42:24+00:00Added an answer on June 17, 2026 at 10:42 pm

    Using your custom MySQL class, this will probably work:

    $result = $db->Query("SELECT `site_url`,`image_url` FROM `adverts` WHERE `zone`=1 AND `days`>0 ORDER BY RAND() LIMIT 0,1;");
    
    while($row = $db->FetchArray($result)) {
        echo '<a href="' . $row['site_url'] . '"><img src="' . $row['image_url'] . '"></a>';
    }
    
    $db->FreeResult($result);
    

    However, as others have pointed out, the code used in your custom MySQL class is deprecated and should be updated to use newer php methods/libraries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble with URLs stored in my database not displaying properly. Here
I'm having trouble displaying my mysql table using php code. All it displays is
This is not allowed in Mysql: SELECT CAST(0 as DOUBLE) as ZERO How do
Hi Order By not working on MySql the code is as follows, select *
Is it possible to select records in a mysql database that does not start
The current issue I'm facing is that my MySql tables are not displaying when
I wrote some PHP code that will allow me to create an html dropdown
I wrote a code for getting latitude and longitude values from database and displaying
I am very new to PHP/MySQL and I don't know the best toolset or
I am trying to display from a MySQL Database using PHP and Ajax but

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.