3

Actualy I have to populate table data using php array to my dashboard. The table contains the URL. I need to set href which is used to redirect to the dynamic link.(below is my while loop code). I have tried creating href using below the single line echo php code.It worked and I got the clickable link, but it didn't return data inside the table. It showed the data in the table without any alignment.

echo '<html><head></head><a href="'.$data['link'].'" target="_blank">'.$data['link'].'</a></html>';  

But I want to create href inside array kindly anyone help us.

public function getTemperatures()
{
    $mysql_hostname = "localhost";
    $mysql_user     = "root";
    $mysql_password = "";
    $mysql_database = "new";
    $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Oops some thing went wrong");
    mysql_select_db($mysql_database, $bd) or die("Oops some thing went wrong");// we are now connected to database

    $result = mysql_query("SELECT * FROM website"); // selecting data through mysql_query()
    $pie = mysql_query("select count(*) from website where status = 'Error'");

    while($data = mysql_fetch_array($result))
    {
        //echo '<html><head></head><a href="'.$data['link'].'" target="_blank">'.$data['link'].'</a></html>';
        $temperatures[] = array(
            'label1' => $data['link'],
            'label2' => $data['time'],
            'label3' => $data['os'],
            'label4' => $data['browser'],
            'label5' => $data['status'],
            'label6' => $data['location'],
            array('label6' => $data['widget_load_time'])
        );
    }    
    return DataTable::makeFromIndexedArray($temperatures);
}
7
  • 2
    You really need to stop using mysql_ functions Commented Sep 18, 2015 at 13:44
  • Where's your <body>-Tag? Are you trying to echo several html elements? That won't work. Wrap your html (and body) around the whole thing. Commented Sep 18, 2015 at 13:50
  • mysql_* extensions have been removed in PHP 7. Learn about prepared statements instead, and consider using PDO, it's really not hard. Commented Sep 18, 2015 at 13:50
  • Add error checking, such as or die(mysql_error()) to your queries. Or you can find the issues in your current error logs. Commented Sep 18, 2015 at 13:51
  • 1
    Your question and your code do not seem to have anything to do with each other. VTC as unclear! Commented Sep 18, 2015 at 14:00

2 Answers 2

2

pls add this line

'label1' => '<a href="'.$data['link'].'" target="_blank">'.$data['link'].'</a>',
Sign up to request clarification or add additional context in comments.

Comments

1

Looks like you have the solution already. Just change how you assign 'label1' to the below.

public function getTemperatures()
{
    $mysql_hostname = "localhost";
    $mysql_user     = "root";
    $mysql_password = "";
    $mysql_database = "new";
    $bd =  mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Oops some thing went wrong");
    mysql_select_db($mysql_database, $bd) or die("Oops some thing went wrong");// we are now connected to database

    $result = mysql_query("SELECT * FROM website"); // selecting data through mysql_query()
     $pie = mysql_query("select count(*) from website where status = 'Error'");

    while($data = mysql_fetch_array($result))
    {
        $temperatures[] = array(
            'label1' => '<a href="'.$data['link'].'" target="_blank">'.$data['link'].'</a>',
            'label2' => $data['time'],
            'label3' => $data['os'],
            'label4' => $data['browser'],
            'label5' => $data['status'],
            'label6' => $data['location'],
            array('label6' => $data['widget_load_time'])
        );
    }    
    return DataTable::makeFromIndexedArray($temperatures);
}

And as the comments mentioned, avoid using mysql_* functions as they're no longer supported (which should be reason enough)

2 Comments

Why are you "kinda' guessing"? A good answer will always have an explanation of what was done and why it was done that way, not only for the OP but for future visitors to SO.
@jay guessing cause I'm not sure what he's asking for. I'll edit my answer to atleast explain what it does. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.