Jump to content

Generating a link in php from mysql database.


cuboidgraphix

Recommended Posts

Hello guys,

    In the past you have all been very helpful to me. This is an ongoing project I'm working on and it's time for an upgrade. I'm trying to design a page that when it loads up, it shows a statistics table. On the first column, I'm trying to generate links that will be integrated with AJAX, that will generate another mysql query and break down in another "sub table" that will slide under the row. Each row will be a different table, only visible when clicking on the link on the first column.

 

So far this is a chunk of my output code.

 

<?php
// This is the query that generates the table.
$query = "SELECT CONCAT('BTS10',(SUBSTRING(LPAD(CELL,5,0),1,2))) AS 'BTS No.', Date, SUM(CALL_ATTEMPTS) AS 'Attempt', SUM(CALL_SUCCESS) AS 'Success', (SUM(CALL_SUCCESS)/SUM(CALL_ATTEMPTS))*100 AS '% Succ.', SUM(BLOCKS) AS 'Block', (SUM(BLOCKS)/SUM(CALL_ATTEMPTS))*100 AS '% Block', SUM(FAILS) AS 'Fail', (SUM(FAILS)/SUM(CALL_ATTEMPTS))*100 AS '% Fail', SUM(SCREEN_CALLS) AS 'Screen', (SUM(SCREEN_CALLS)/SUM(CALL_ATTEMPTS))*100 AS '% Screen', SUM(DROP_CALLS) AS 'Drop', (SUM(DROP_CALLS)/SUM(CALL_SUCCESS))*100 AS '% Drop' FROM PERCELL WHERE DATE = '$fecha' AND TYPE = '24 HOURS' GROUP BY 'BTS No.'";

$data = mysql_query("$query;") or die(mysql_error());					

// Table Output	
print "<table width=\"800\">";
print "<tr>";
for($i = 0;$i < mysql_num_fields($data);$i++)
    {
    $fieldname =  mysql_field_name($data, $i);
    print "<th>" .$fieldname . "</th>";
    }
print "</tr>";
for ($i = 0; $i < mysql_num_rows($data); $i++)
    {
    print "<tr>";
    $row = mysql_fetch_row($data);
        for($j = 0;$j < mysql_num_fields($data);$j++)
            {
            $fieldname =  mysql_field_name($data, $j);
            if ($fieldname === "Type") {
                $hrs = str_replace('HOURS', "HRS", $row);
                } elseif ($fieldname === "BTS No."){
                /* Here is where i want to put the script that will generate the links on the first column (BTS No.)
                   This table generates 30 rows, that will have an AJAX effect that will 'Accordion' into another 'SubTable' below each row
                   whenever someone clicks on the generated links in the first row. As for the subtables, it will require a separate mysql query to generate it. 
                   Note: The Links will be the same name/value as the value in the database. eg rows: BTS1001 , BTS1002 , BTS1003 ... etc. */
                } else {
                $hrs = $row;
                }
            echo("<td class=\"".color($fieldname, $hrs[$j])."\">" . $hrs[$j] . "</td>");			
            }
    print "</tr>";
    }
print "</table>";
?>

 

Anyways I hope one of you guys can help me out. I've been at it for two days and nothing seems to work. I'm not an expert, but I do read up a lot. If you could help me out I'll really appreciate it.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.