Support » Fixing WordPress » Display names with inline links for address detail using an external database

  • On a single WP page I am looking to display a list of customer names from a database table in an external database. If a user clicks on any name in that list then I want to display additional info (address, phone no, etc.) just below the just-clicked name.

    Note that the additional info (address, phone no., etc.) will also come from the same external table.

    For security reasons I do not want to grab all the data from the external table at once and then do a simple SHOW/HIDE DIV toggle to reveal the address info; I would rather display all the names at once, but only when a name is clicked do I want to display the other info for that person.

    (From the user’s viewpoint they would see the initial list of names. They would click on a name and the entire list would shift down one line and the clicked name’s address and other info would be displayed, and all the names below that would shift down one line)

    I already have some pseudo code (below) for accessing the external table and then looping thru it and displaying the retrieved names in some type of HTML list:

    $db1 = mysql_connect( 'localhost', 'db_username', 'db_password' ) or die( mysql_error() );
    $sel1 	= mysql_select_db( 'db_name' ) or die( mysql_error() );
    $query = "SELECT name-and-ID FROM some_table";
    $res1 = mysql_query( $query, $db1 );
    while ( $array = mysql_fetch_array( $res1 ) ){
    	print_r( $array );

    How would I add the functionality to this dynamic list that would allow a user to click on any name in the list to see additional info about that name?

    I expect that I would need to add a hyperlink next to each name that – when clicked – would invoke another WP page and pass it the clicked ID, and it in turn would invoke some logic (perhaps a custom function?) to retrieve that ID’s address, and phone no. from the same external table and then display it inline within my dynamic list.

    I am just not sure of the best way to do this. Any suggestions?

  • The topic ‘Display names with inline links for address detail using an external database’ is closed to new replies.