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);
}
Baskar .A
  • 570
  • 4
  • 10
  • 2
    You really need to [stop using mysql_ functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Machavity Sep 18 '15 at 13:44
  • Where's your ``-Tag? Are you trying to echo several `html` elements? That won't work. Wrap your `html` (and body) around the whole thing. – m02ph3u5 Sep 18 '15 at 13:50
  • [`mysql_*` extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) [statements](http://php.net/manual/en/pdo.prepared-statements.php) instead, and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Sep 18 '15 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. – Jay Blanchard Sep 18 '15 at 13:51
  • 1
    Your question and your code do not seem to have anything to do with each other. VTC as unclear! – RiggsFolly Sep 18 '15 at 14:00
  • Baskar..I'm unclear on exactly what your wanting your results to look like. Can you show us what your expecting to see ? – Jim_M Sep 18 '15 at 14:02
  • @Machavity i really loved your comment :D – Halayem Anis Sep 18 '15 at 14:03

2 Answers2

2

pls add this line

'label1' => '<a href="'.$data['link'].'" target="_blank">'.$data['link'].'</a>',
Baskar .A
  • 570
  • 4
  • 10
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)

  • 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 Blanchard Sep 18 '15 at 14:18
  • @jay guessing cause I'm not sure what he's asking for. I'll edit my answer to atleast explain what it does. Thanks. –  Sep 18 '15 at 14:21