Jump to content

Need to display mysql query results after clicking hyperlink


kel

Recommended Posts

Hi

 

I'm trying to create a system that amongst other things displays data (in this case printer information) from a mysql database. I have created a page that displays some stuff in a table with the number of records displayed and hyperlinked next to it. Each count depends on the status of each record (e.g. by date). Anyway, what I am trying to do is as follows:

 

When the respective count/total hyperlink is selected, then I want the data that this total represents to be pulled from the database and displayed (maybe in a table) below the table and hyperlinks (see above).

 

something like:

 

Total printers on site - some number (hyperlinked)

Printers that require maintenance - some number (h/linked)

blah

blah

 

and then when whichever link is selected, the respective data should be displayed here (bearing in mind that the data returned will be hyperlinked too - but I think I can do that bit) - I can send it to a different page (using POST) but what I really want is for it to display on the same page as the totals.

 

Here is my code so far: As you can see i want to use a function (see top of code) to display this stuff, preferably want a reusable function that will display depending on the hyperlink selected.

 

<?php

function listAllPrinters()

{

        print "hi";  //function to get data displayed under table

}

?>

<Html>

<Head><B><font size = "18">Printer Maintenance</font></Head>

<Body>

<?php $db_link = mysql_connect('localhost', 'deeb', 'deeb');?>  <! db_link is just a variable name, could've called it foo, this bit connection to mysql server -->

<?php if (!$db_link)

{

die('Could not connect: ' . mysql_error());

}

?>

<?php $db_selected = mysql_select_db('maint_db', $db_link); ?> <! selects the relevant database -->

<?php $db_link = mysql_connect('localhost', 'deeb', 'deeb');?>

<?php if (!$db_link)

{

die('Could not connect: ' . mysql_error());

}

?>

<?php $db_selected = mysql_select_db('maint_db', $db_link); ?> <! selects the relevant database -->

<?php

 

//All printers

$prt_count = mysql_query("SELECT asset_tag, serial, prt_name, sched_date FROM item");

$prt_num = mysql_num_rows($prt_count);

 

//printers that need maintaining

$maint_count = mysql_query("SELECT * FROM item WHERE sched_date < Date_sub(current_date(), interval 3 month)");

$maint_num = mysql_num_rows($maint_count);

 

//Printers that are overdue for maintenance

$over_count = mysql_query("SELECT * FROM item WHERE sched_date < Date_sub(current_date(), interval 4 month)");

$over_num = mysql_num_rows($over_count);

?>

<TABLE BORDER=1><TR BGCOLOR="RED"></TR>

<TD><B>PRINTERS (HP AND ZEBRA)</TD>

<TD>

        <?php echo ("<A HREF=\"maint_index.php?action=printall\">$prt_num</A>\n"); ?> <!displays the number of printers and hyperlinks the result -->

</TD>

</TR>

<TR>

<TD><B>PRINTERS REQUIRING MAINTENANCE</TD>

<TD>

        <?php echo ("<A HREF=\"maint_index.php?action=printall\">$maint_num</A>\n"); ?> <!displays the number of printers that are due for maintenance and hyperlinks the result -->

</TD>

</TR>

<TR>

<TD><B>MAINTENANCE OVERDUE</TD>

<TD>

        <?php echo ("<A HREF=\"maint_index.php?action=printall\">$over_num</A>\n"); ?> <!displays the numer of printers that are overdue for maintenance and hyperlinks the result -->

</TD>

</TR>

</TABLE>

<BR>

<?php

if ( $_GET['action'] == "printall" )

{

    listAllPrinters();

}

?>

</Body>

</Html>

 

Suggestions welcome - I'm fairly new to all of this stuff

 

Thanks

 

 

Link to comment
Share on other sites

Looks Ok, except you need 3 different action values such as all, maint and over.  Then test for each via $_GET[] just like you have and display your results.

 

What else do you need help with?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.