- This topic is empty.
-
AuthorPosts
-
November 17, 2009 at 5:48 am #26794
brad_langdon
MemberIn 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:“;
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
} ?>
“;
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 ““; // SIGN OUT USER
echo ““;
}
}} ?>
Just use mysql_fetch_array() to, well fetch an array of the query results.
- The forum ‘Back End’ is closed to new topics and replies.