Grow your CSS skills. Land your dream job.

Array Problem

  • # November 17, 2009 at 5:48 am

    In the following code I am trying to insert the result of the mysql query called " $loop3 " into the javascript code that follows the loop. As the code is outside of the loop it only echo’s the last result from the loop.

    I don’t know much about arrays but I am pretty sure I have to store all of the results from " $loop3 " in an array so it can be used out of the loop. Can someone please explain how to do this.

    Please explain carefully as I don’t know too much about arrays. The loop and javascript snippet is about halfway down through the code.

    Code:
    < ?php $loop = mysql_query("SHOW tables FROM $data_base") or die ('cannot select tables'); // SELECT ALL TABLES FROM CLIENT DATABASE
    while($row = mysql_fetch_array($loop)){ // SELECT ALL TABLES FROM CLIENT DATABASE

    $loop2 = mysql_query("SELECT * FROM $row[0] ORDER BY date02") or die ('cannot select table fields'); // SELECT ALL CONTENT FROM EACH TABLE
    while ($row2 = mysql_fetch_array($loop2)){ // SELECT ALL CONTENT FROM EACH TABLE

    echo "

    “;
    echo “

    ” . $row2[title] . “

    “;

    $loop3 = mysql_query(“SELECT * FROM $row[0] ORDER BY date02″) or die (‘Cannot select table fields’); // SELECT ALL CONTENT FROM EACH TABLE
    mysql_data_seek($loop3,0); // RESET DATA COUNTER SINCE WHILE LOOP HAS ALREADY BEEN USED
    while ($row3 = mysql_fetch_array($loop3)){

    $date = $row3[date02]; // LIST EACH OCCUPIED DATE IN FORMAT THAT MATCHES CALENDAR JQUERY FORMAT

    $date_a = substr ($date, 0, 4); // PULL YEAR AS SEPERATE VARIABLES SO THEY CAN BE REARRANGED TO FIT CALENDAR FORMAT
    $date_b = substr ($date, 4, 2); // PULL MONTH AS SEPERATE VARIABLES SO THEY CAN BE REARRANGED TO FIT CALENDAR FORMAT
    $date_c = substr ($date, 6, 2); // PULL DAY AS SEPERATE VARIABLES SO THEY CAN BE REARRANGED TO FIT CALENDAR FORMAT

    $date = “”” . $date_b . “/” . $date_c . “/” . $date_a . “”,”; // RE FORMAT DATE TO FIT CALENDAR JQUERY FORMAT

    } ?>

    < ?php
    echo "“;
    echo “

    Booked Dates

    “;

    $loop2 = mysql_query(“SELECT * FROM $row[0] ORDER BY date02″) or die (‘cannot select table fields’); // SELECT ALL CONTENT FROM EACH TABLE
    mysql_data_seek($loop2,0); // RESET DATA COUNTER SINCE WHILE LOOP HAS ALREADY BEEN USED
    while ($row2 = mysql_fetch_array($loop2)){
    echo “

  • ” . $row2[date] . “
  • “; // LIST EACH OCCUPIED DATE AND LINK TO DELETE.PHP TO DELETE RECORD
    }

    echo “

    “;
    echo “

    Logout

    “; // SIGN OUT USER
    echo “

“;

}
}

} ?>

# November 17, 2009 at 7:54 am

Just use mysql_fetch_array() to, well fetch an array of the query results.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".