0

I just need to create a simple php page that can query one table(ad_data), and compare two columns against rows in another table(time_clock_data), and return the value of the column 'Login Name' in time_clock_data. However, when i run the page it pulls everything from ad_data fine, but the time_clock_data 'Login Name' returns null.

Here is my code:

<?php

    mysql_connect("localhost", "root", "") or die (mysql_error ());
    $conn = new mysqli("localhost", "root", "", "uh_time_clock");

    mysql_select_db("uh_time_clock") or die(mysql_error());

    function queryAd(){

        $adQuery = mysql_query("SELECT * FROM ad_data ORDER BY 'First Name' DESC");
        while($ad = mysql_fetch_array($adQuery)) {

            $adFirstName = $ad['First Name'];
            $adLastName = $ad['Last Name'];
            $adLoginName = $ad['Login Name'];

            echo "<li>" . $adLoginName . "</li>";

            mysql_select_db("uh_time_clock") or die(mysql_error());

            $tcQuery = "SELECT * FROM time_clock_data WHERE 'First Name' = '$adFirstName' and 'Last Name' = '$adLastName'";
            $tc = mysql_fetch_assoc( mysql_query($tcQuery) );

            $tcLoginName = $tc['Login Name'];

            echo "<li>" . $tcLoginName . "</li>";

        }
    }

    queryAd();

    mysql_close();

    ?>
3
  • you selected the database 2 times Commented Mar 30, 2015 at 13:07
  • add mysql_query( $tcQuery ) after your second query. Commented Mar 30, 2015 at 13:08
  • You can't run your 2nd query while your 1st is not finished. And do not use mysql. Use mysqli or pdo. See stackoverflow.com/questions/13202261/… Commented Mar 30, 2015 at 13:08

0

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.