Perform a query without a view I've created msyql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lovelf
Forum Contributor
Posts: 153
Joined: Wed Nov 05, 2008 12:06 am

Perform a query without a view I've created msyql

Post by lovelf »

The following is the queries:

Code: Select all

<?php
mysql_query("CREATE VIEW F1LIMIT5 as SELECT DISTINCT albumid from tags WHERE id3='$value' AND flag!='w' AND visibility='t' ORDER BY datetimep DESC limit 5");

$aresult=mysql_query("SELECT * from tags where albumid in (SELECT * FROM F1LIMIT5) and id3='$value' AND flag!='w' AND visibility='t' order by datetimep desc"); 
?>
I would need not to use the create view query, and instead make it a single query, substitute the select * from f1limit5
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Perform a query without a view I've created msyql

Post by McInfo »

I'm not sure what you are asking for.
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Re: Perform a query without a view I've created msyql

Post by Mordred »

What you do:

CREATE VIEW myview AS SELECT <subselect>
SELECT x IN (SELECT * FROM myview) ...

What you can do:
SELECT x in (<subselect>) ...
lovelf
Forum Contributor
Posts: 153
Joined: Wed Nov 05, 2008 12:06 am

Re: Perform a query without a view I've created msyql

Post by lovelf »

Doing this:

Code: Select all

<?php
$aresult=mysql_query("SELECT * from tags where albumid in (DISTINCT albumid from tags WHERE id3='$valued' AND flag!='w' AND visibility='t' ORDER BY datetimep DESC limit 5) and id3='$value' AND flag!='w' AND visibility='t' order by datetimep desc");
?> 
Returns php errors, I really want to get rid of the view.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Perform a query without a view I've created msyql

Post by McInfo »

Maybe this?

Code: Select all

$aresult = mysql_query(sprintf("SELECT * FROM tags WHERE id3='%s' AND flag!='w' AND visibility='t' ORDER BY datetimep DESC", mysql_real_escape_string($value)));
Post Reply