CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
sql optimization... ?

 



mike_robb
Novice

Feb 13, 2001, 4:00 PM

Post #1 of 4 (320 views)
sql optimization... ? Can't Post

Does anyone know a better way to do this:
(this works - but doesn't seem like the best way to do it..)


function exampleWithHightestCount()
{
$return_var=-1; // none found
$query = "SELECT COUNT FROM EX_VIEW_COUNT ORDER BY COUNT";
$temp1=-1;
$temp2=-1;
$temp3=-1;
$temp4=-1;
$temp5=-1;
$temp6=-1;
$temp7=-1;
$temp8=-1;
$temp9=-1;
$temp10=-1;
if ($result = mysql_query($query))
{
while ($row = mysql_fetch_array($result))
{
$temp10=$temp9;
$temp9=$temp8;
$temp8=$temp7;
$temp7=$temp6;
$temp6=$temp5;
$temp5=$temp4;
$temp4=$temp3;
$temp3=$temp2;
$temp2=$temp1;
$temp1=$row[COUNT];
}
}
$query = "SELECT EX_ID,COUNT FROM EX_VIEW_COUNT WHERE EX_VIEW_COUNT.COUNT LIKE '$temp1'";if ($result = mysql_query($query)){while ($row = mysql_fetch_array($result)){$return_var=$row[EX_ID];echo "<a href='$MY_FILE_EXAMPLE?ex=".$return_var."'>".$return_var."</a> | ";}}
$query = "SELECT EX_ID,COUNT FROM EX_VIEW_COUNT WHERE EX_VIEW_COUNT.COUNT LIKE '$temp2'";if ($result = mysql_query($query)){while ($row = mysql_fetch_array($result)){$return_var=$row[EX_ID];echo "<a href='$MY_FILE_EXAMPLE?ex=".$return_var."'>".$return_var."</a> | ";}}
$query = "SELECT EX_ID,COUNT FROM EX_VIEW_COUNT WHERE EX_VIEW_COUNT.COUNT LIKE '$temp3'";if ($result = mysql_query($query)){while ($row = mysql_fetch_array($result)){$return_var=$row[EX_ID];echo "<a href='$MY_FILE_EXAMPLE?ex=".$return_var."'>".$return_var."</a> | ";}}
$query = "SELECT EX_ID,COUNT FROM EX_VIEW_COUNT WHERE EX_VIEW_COUNT.COUNT LIKE '$temp4'";if ($result = mysql_query($query)){while ($row = mysql_fetch_array($result)){$return_var=$row[EX_ID];echo "<a href='$MY_FILE_EXAMPLE?ex=".$return_var."'>".$return_var."</a> | ";}}
$query = "SELECT EX_ID,COUNT FROM EX_VIEW_COUNT WHERE EX_VIEW_COUNT.COUNT LIKE '$temp5'";if ($result = mysql_query($query)){while ($row = mysql_fetch_array($result)){$return_var=$row[EX_ID];echo "<a href='$MY_FILE_EXAMPLE?ex=".$return_var."'>".$return_var."</a> | ";}}
$query = "SELECT EX_ID,COUNT FROM EX_VIEW_COUNT WHERE EX_VIEW_COUNT.COUNT LIKE '$temp6'";if ($result = mysql_query($query)){while ($row = mysql_fetch_array($result)){$return_var=$row[EX_ID];echo "<a href='$MY_FILE_EXAMPLE?ex=".$return_var."'>".$return_var."</a> | ";}}
$query = "SELECT EX_ID,COUNT FROM EX_VIEW_COUNT WHERE EX_VIEW_COUNT.COUNT LIKE '$temp7'";if ($result = mysql_query($query)){while ($row = mysql_fetch_array($result)){$return_var=$row[EX_ID];echo "<a href='$MY_FILE_EXAMPLE?ex=".$return_var."'>".$return_var."</a> | ";}}
$query = "SELECT EX_ID,COUNT FROM EX_VIEW_COUNT WHERE EX_VIEW_COUNT.COUNT LIKE '$temp8'";if ($result = mysql_query($query)){while ($row = mysql_fetch_array($result)){$return_var=$row[EX_ID];echo "<a href='$MY_FILE_EXAMPLE?ex=".$return_var."'>".$return_var."</a> | ";}}
$query = "SELECT EX_ID,COUNT FROM EX_VIEW_COUNT WHERE EX_VIEW_COUNT.COUNT LIKE '$temp9'";if ($result = mysql_query($query)){while ($row = mysql_fetch_array($result)){$return_var=$row[EX_ID];echo "<a href='$MY_FILE_EXAMPLE?ex=".$return_var."'>".$return_var."</a> | ";}}
$query = "SELECT EX_ID,COUNT FROM EX_VIEW_COUNT WHERE EX_VIEW_COUNT.COUNT LIKE '$temp10'";if ($result = mysql_query($query)){while ($row = mysql_fetch_array($result)){$return_var=$row[EX_ID];echo "<a href='$MY_FILE_EXAMPLE?ex=".$return_var."'>".$return_var."</a>";}}
}



TIA

--Mike
(http://www.js-examples.com)



muinatit
Deleted

Feb 14, 2001, 12:20 PM

Post #2 of 4 (312 views)
Re: sql optimization... ? [In reply to] Can't Post

That's JavaScript, and this is a Perl forum.

Jeffrey "muinatit" Lamoureux
muinatit@hotpop.com


mike_robb
Novice

Feb 14, 2001, 4:59 PM

Post #3 of 4 (309 views)
hmm.. are you sure... ? [In reply to] Can't Post

No. It is not javascript. It is actually php (version3) which uses sql to build a page.


Perl users use mysql more than php users. That is the reason this post is in the Perl forum. the question is actually asking about the sql statements - which by the way - would work in PHP or Perl.

I was hoping that someone who reads this forum would also know enough sql to assist me in my quest for a better quicker script.





Jasmine
Administrator

Feb 14, 2001, 10:55 PM

Post #4 of 4 (307 views)
Re: hmm.. are you sure... ? [In reply to] Can't Post

Try nesting your queries with the logical OR operator and if PHP offers a loop funcion, use that to build a single query instead of doing so many separate queries.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives