Jump to content

Recommended Posts

ok so i cant get the create veiw to work .... it will work in phpmyadmin and with dbforge but not in the site... here is the code

my server version is 5.1.36

the errors i get are: either the table comply is not there  or if i exclude the 2nd select statement i get no database selected  but i can run other query's just fine!... and all permissions are set for the user.

 

 

 

 

$sql1=mysql_query(" CREATE VIEW comply AS

SELECT quiz_compliance.grade, quiz.title as 'quiz', course.title as 'course', quiz_compliance.finish, user.first, user.last, user.id

FROM $dbname.course_enrollments

INNER JOIN $dbname.course ON course_enrollments.course_id = course.id

INNER JOIN $dbname.user ON course_enrollments.user_id = user.id

INNER JOIN $dbname.quiz_compliance

INNER JOIN $dbname.quiz ON quiz.course_id = course.id AND quiz_compliance.quiz_id = quiz.id

WHERE quiz_compliance.user_id = user.id AND course.id = '7'

");

 

$sql4=mysql_query(" SELECT user.id, user.`first`, user.`last`

FROM emscloud.user

LEFT OUTER JOIN emscloud.comply ON user.id = emscloud.comply.id

WHERE emscloud.comply.id IS NULL");

 

echo "\n\n";

echo "User ID,Last,First,\n\n";

if ($sql1){

while($s=mysql_fetch_array($sql4)){

$user_id = $s["id"];

$Last_name = $s["last"];

$first_name = $s["first"];

 

 

echo $user_id.",".$Last_name.",".$first_name;

echo "\n";

 

}

}else{ print mysql_error();}

 

Link to comment
https://forums.phpfreaks.com/topic/196249-php-mysql-create-view/
Share on other sites

Try selecting the database first and see if that helps.

 

USE databasename;

 

When you first connect to your database, you should select the database name as well.  Make sure it does that already; if so you don't need to use the above code.

 

Also, check to make sure the View is not already there, if you're testing it, you may have created this table already.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.