Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Variable to create view

Status
Not open for further replies.

mcmon999

IS-IT--Management
Mar 3, 2005
21
GB
Hi,

I'm trying to create a view using a variable entered by the using, i started by using the code below:

<?php
$programid = $_GET['prog_id'];
//echo "$programid";
$period = $_GET['period'];
//echo "$period";
$query=mysql_query("drop view IF EXISTS '$programid';");

$query1=mysql_query("CREATE VIEW '$programid' AS SELECT distinct program_enhancement.Enhancement_id, program_enhancement.program_id, enhancement.Enhancement, enhancement.Task, enhancement.frequency, max(date) Date FROM enhancement, program_enhancement WHERE enhancement.enhancement_id = program_enhancement.enhancement_id and program_id = '$programid' group by task;"); ?>

Is it possible to create a view using a variable enter by a user?

Thanks in advance,
 
yes. but your query looks malformed.

* you might have an ambiguity in your group by clause and your where clause
* the word date (nor any other reserved word) cannot be used as a column name without be surrounded with backticks (NOT quotes nor double quotes).
* should max(date) Date be max(`date`) AS `Date`?
* you should include some debug code in your scripts
Code:
$result = mysql_query("some query") or die (mysql_error());
it often helps to echo the query to the screen too.
* view and table names are not enquoted. only values are. so this
Code:
CREATE VIEW '$programid'
is not going to work. get rid of the quotes and either leave unsurrounded or put backticks front and back.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top