vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Repeating the same query (https://vborg.vbsupport.ru/showthread.php?t=93056)

Lionel 07-28-2005 07:40 AM

Repeating the same query
 
I am doing a query where the choices are title=$extra1 or title=$extra2 or title=$extra3 (up to 6 extras)

I am getting the same result for all, and I ended up doing the below 6 times.

Surely there must be another way to do this to avoid the 6 queries?

PHP Code:

 $extra1songsquery $DB_site->query("SELECT songid, title, url FROM soundtracks WHERE title='$extra1' AND 
active=1"
);
while(
$extra1songrow $DB_site->fetch_array($extra1songsquery)) 
        {    
         
$clip1=$extra1songrow['title'];
    
$clip1id=$extra1songrow['songid'];
    
$clip1url=$extra1songrow['url'];
    
$extra1="<a href=\"showproduct.php?product=$product&do=main&mysong=$clip1id\">$clip1</a>"
        } 
 
$extra2songsquery $DB_site->query("SELECT songid, title, url FROM soundtracks WHERE title='$extra2' AND 
active=1"
);
while(
$extra2songrow $DB_site->fetch_array($extra2songsquery)) 
        {    
         
$clip2=$extra2songrow['title'];
    
$clip2id=$extra2songrow['songid'];
    
$clip2url=$extra2songrow['url'];
    
$extra2="<a href=\"showproduct.php?product=$product&do=main&mysong=$clip2id\">$clip2</a>"
        } 


Andreas 07-28-2005 07:47 AM

PHP Code:

$DB_site->query("SELECT songid, title, url FROM soundtracks WHERE title IN ('$extra1', '$extra2', '$extra3') AND active=1"); 

?

Boofo 07-28-2005 07:48 AM

Can't you do a:

Quote:

SELECT * FROM

Lionel 07-28-2005 07:58 AM

Quote:

Originally Posted by KirbyDE
PHP Code:

$DB_site->query("SELECT songid, title, url FROM soundtracks WHERE title IN ('$extra1', '$extra2', '$extra3') AND active=1"); 

?

That does not return the other items (url and songid).
This is a non Vb script where I cannot do a normal eval for a templatebit.
when I do:

PHP Code:

 $extra1songsquery $DB_site->query("SELECT songid, title, url FROM soundtracks WHERE WHERE title IN ('$extra1', '$extra2', '$extra3') AND active=1");
 
while(
$extra1songrow $DB_site->fetch_array($extra1songsquery)) 
        {    
         
$clip1=$extra1songrow['title'];
    
$clip1id=$extra1songrow['songid'];
    
$clip1url=$extra1songrow['url'];
    
$extra1="<a href=\"showproduct.php?product=$product&do=main&mysong=$clip1id\">$clip1</a>"
        } 

and put in template:

$extra1

only the first one is returned. The others have no results.

Quote:

Originally Posted by Boofo
Can't you do a:

can't do that. It's the WHERE clause that is giving me a hard time. Too many WHERE

Andreas 07-28-2005 08:02 AM

I dont seem to understand your problem :)

Please post a scheme of your Table with example Data, the values for extra1, extra2, etc. and what you would like to have returned.

But I think your problem does have nothing to do with the query:

PHP Code:

$extra1.="<a href=\"showproduct.php?product=$product&do=main&mysong=$clip1id\">$clip1</a>"


Lionel 07-28-2005 08:11 AM

OK, here is what I am doing:

When I input the data in that page

I have $desc which I am using to parse Geek autolink to lyrics.
I have 6 extra fields that I could use. I am using them to query a database of MP3s. I put the exact title in the various extra fields. Then I do a query in the php. If the soundtracks title matches one of the extras, then I need to get the info for each one of the extras (I have embeded a player in the page and when you click on the link at the bottom of the page, it plays the selected clip). My method works, but I have to do the same query six times.

Andreas 07-28-2005 08:14 AM

The linked page is in french and I understand nothing :)

Please, just post your table scheme, example data, the extraX values and which rows you want to have selected for those.

Lionel 07-28-2005 08:19 AM

Oh well, sorry for the French.

I am no guru. What you saw is from painfully put together hours of trial and error spaghetti codes. I don't even know what you mean by schema.

Boofo 07-28-2005 08:23 AM

Quote:

Originally Posted by Lionel
Oh well, sorry for the French.

I am no guru. What you saw is from painfully put together hours of trial and error spaghetti codes. I don't even know what you mean by schema.

schema=scheme?

Andreas 07-28-2005 08:23 AM

This is the scheme of Table datastore:

Code:

CREATE TABLE `datastore` (
  `title` varchar(15) NOT NULL default '',
  `data` mediumtext  NOT NULL,
  PRIMARY KEY  (`title`)
);

And this is example Data for this Table:
Code:

INSERT INTO `datastore` VALUES ('cron', '1122540900');
INSERT INTO `datastore` VALUES ('banemail', '');

Or in other words: A (part) dump of the Table.


All times are GMT. The time now is 01:54 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01793 seconds
  • Memory Usage 1,755KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (5)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete