|
-
Oct 13th, 2007, 05:11 PM
#1
[RESOLVED Temporarily] Filtering
Is it possible to filter a resultset of a db query? I dont want to hit the db with two calls and my query is joined to bring the related resultset back but upon iterating it may be best to loop through the one condition and then reloop through the other. There will be no duplication of items in the loop so its not a resource drain or waste.
For ex. if you have returned items that can be visible and invisible then it would be a waste to call the db twice just to loop through the visible ones and then another call and loop through the invisible ones. So if I have 5 visible and 5 invisible items then I only want to loop a total of 10 times; filter for visible, loop 5 times, unfilter, refilter for invisible, loop 5 more times and release resources.
Thanks
Last edited by RobDog888; Oct 13th, 2007 at 10:18 PM.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 13th, 2007, 05:16 PM
#2
Re: Filtering
you can use the WHERE clause.
SELECT * FROM `mytable` WHERE visibility='visible'
SELECT * FROM `mytable` WHERE visibility='invisible'
are you talking about a while loop?
PHP Code:
while ($res = mysql_fetch_array($query)) {
print_r($res);
}
My usual boring signature: Something
-
Oct 13th, 2007, 05:18 PM
#3
Re: Filtering
Yes, I know the where clause but I dont want to make 2 db calls. 
Yes, in the loop fetch stuff
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 13th, 2007, 05:21 PM
#4
Re: Filtering
In ADO recordsets you can filter the recordset to prevent multiple db calls and allow efficient looping etc.
In php I am not sure if there is anything similar to this?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 13th, 2007, 05:29 PM
#5
Re: Filtering
I looked around, and i cant find anything. why dont you want to make 2 queries?
My usual boring signature: Something
-
Oct 13th, 2007, 05:41 PM
#6
Re: Filtering
Trying to keep overhead to a minimum. Db calls are resource expenses.
The best I can get it to do a complex ORDER BY clause to create them in a logical order for looping where visible are ordered first and then the invisible ones. Its still going to require 20 iterations as I can not count on the data being 100% accuarate based unpon the complex ordering. Otherwise I would just process the first results as visible and the later ones as not but its not reliable programming logic.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 13th, 2007, 08:01 PM
#7
Re: Filtering
Can I loop again after the first loop is done?
PHP Code:
while ($res = fetch_array($results))
{
//Blah
}
while ($res = fetch_array($results))
{
// double Blah
}
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 13th, 2007, 09:08 PM
#8
Re: Filtering
you can, but that will just spit out the same info from the one above.
I think you are going to need 2 queries:
PHP Code:
$sql1 = "SELECT * FROM `mytable` WHERE blah='blah'";
$sql2 = "SELECT * FROM `mytable` WHERE blah='noblah'";
$query1 = mysql_query($sql1);
$query2 = mysql_query($sql2);
while ($res1 = mysql_fetch_array($query1)) {
}
while ($res2 = mysql_fetch_array($query2)) {
}
do you want it to echo like:
visible
visible
visible
visible
invisible
invisible
invisible
?
My usual boring signature: Something
-
Oct 13th, 2007, 10:01 PM
#9
Re: Filtering
I already ended up putting something like that in place for now until I can find a more efficient way. This is what I didnt want to end up doing with a secondary db call.
In VB 6 you can reuse recordsets depending on how they are opened. I guess ph is still too wimpy. 
I have a new issue that I have been working on for a bit now (see new thread).
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 14th, 2007, 09:46 AM
#10
Re: Filtering
 Originally Posted by RobDog888
Can I loop again after the first loop is done?
Yes. Or you could use an ORDER BY visible=1 clause. Or you could just enumerate the records once and branch.
I guess I'm not quite sure where the problem is...
-
Oct 14th, 2007, 12:50 PM
#11
Re: [RESOLVED Temporarily] Filtering
yeah i didnt quite understand what you were trying to do either... well good luck
My usual boring signature: Something
-
Oct 14th, 2007, 02:27 PM
#12
Re: [RESOLVED Temporarily] Filtering
Well I put in the dual db calls for now but I will change it later once its finished and we polish it up. I dont like depending on the order by clause to present the listing correctly as its not good logic of dependable.
So I cant do like #7 which is more reliable?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 14th, 2007, 02:33 PM
#13
Re: [RESOLVED Temporarily] Filtering
If an ORDER BY clause wasn't reliable it would be useless.
I think I know what you're doing.
How about this?:
PHP Code:
$records = $db->query_read('SELECT blah.* FROM blah ORDER BY (blah.visible=TRUE) ASC');
while ($row = $db->fetch_array($records) && !$row['visible'])
{
# non-visible items
}
while ($row = $db->fetch_array($records))
{
# visible items
}
Edit: Scupper that: that'll enumerate the non-visible items twice if there are one or more non-visible items and no visible items.
Last edited by penagate; Oct 14th, 2007 at 02:37 PM.
-
Oct 14th, 2007, 02:39 PM
#14
Re: [RESOLVED Temporarily] Filtering
Yes, I just wasnt sure if the fetch_array would work twice as it may not have been scrollable, was my worry. The docs sstate it uses a pointer to read the recordset but fails to mention if its cached and is scrollable etc.
Yes, you are thinking correct.
Ps, check out the page its on as its FINISHED
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 14th, 2007, 02:42 PM
#15
Re: [RESOLVED Temporarily] Filtering
fetch_array returns each item in order, until you pass the last item, at which point it returns NULL and resets the pointer to the start. The recordset is cached; fetch_array merely enumerates it. Using a server-side cache (cursor) is somewhat trickier, and unnecessary in this situation.
-
Oct 14th, 2007, 02:45 PM
#16
Re: [RESOLVED Temporarily] Filtering
So then if you looped through the first 5 items as visible when you went to loop through the next 5 invisible items it should start at item 6.
I just dont like counting on counting as there may be instances where the data may be slightly inaccurate and this may lead to other issues.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|