louis_coetzee Posted September 5, 2009 Share Posted September 5, 2009 Please help me, can't figure out what i am doing wrong. Error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\pharma_edu\lib\database.php on line 22 This is all the code needed for you to see what the problem might be. <?php # Connects to database server and selects database. # Returns bool. function db_connect() { $connection = mysql_pconnect(HOST, USERNAME, PASSWORD); if (!$connection) { return false; } if (!mysql_select_db(DATABASE)) { return false; } return $connection; } # Turns MYSQL resource into array. # Returns Array. function result_to_array($result) { $result_array = array(); for ($i=0; $row = mysql_fetch_array($result) ; $i++) { $result_array[$i] = $row; } return $result_array; } function courses_list() { db_connect(); $result_count = mysql_query("SELECT * FROM courses_available"); $num_rows = mysql_num_rows($result_count); $result = array(); for ($i = 1; $i <= $num_rows; $i++) { $query1 = "SELECT * FROM courses_available WHERE courses_available.id = '$i'"; $result1 = mysql_query($query1); $result1 = result_to_array($result1); $course_id = $result1['course_id']; $query2 = "SELECT * FROM courses_list WHERE courses_list.course_id = '$course_id'"; $result2 = mysql_query($query2); $result2 = result_to_array($result2); array_merge($result1, $result2, $result); } return $result; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/173240-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-resultplease-help/ Share on other sites More sharing options...
sKunKbad Posted September 5, 2009 Share Posted September 5, 2009 I'm pretty sure that error means that your query was bad. Try running your query directly on MySQL or phpMyAdmin and see what you get. Quote Link to comment https://forums.phpfreaks.com/topic/173240-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-resultplease-help/#findComment-913202 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.