FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Will this work?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Will this work? [SOLVED] [message #172290 is a reply to message #172244] Thu, 10 February 2011 17:05 Go to previous message
Derek Turner is currently offline  Derek Turner
Messages: 48
Registered: October 2010
Karma:
Member
On Mon, 07 Feb 2011 23:03:15 +0000, Derek Turner wrote:

> How long and complicated can a while condition be?
>
> I want to:
>
> define a string variable ($i) starting at "01" use this in a mysql query
> increment the string
> dropout of the while when a zero result comes back from mysql

Many thanks for help received here. Final working code is:

<?php
// first connect to the database table (cantabi1_choir)
include("/home/cantabi1/member_connect.php");

//create a queries in for/next loop

$fmt = "SELECT `workName`, `composer`, SUBSTRING(`Reference`,
LOCATE('%02d-', `Reference`)) as TRACK FROM `work` WHERE `Reference`
LIKE '%%%02d-%%' ORDER BY TRACK";

// Now we look for disk numbers from 01 to 99

for ($i = 1; $i < 100; $i++){
$result = mysql_query(sprintf($fmt,$i,$i)) or die(mysql_error());
if (mysql_num_rows($result) == 0) break; // empty result set,
finished //

//process each $result
....
?>

The sprintf() function made the backslashes (needed in the simple assign
string) redundant (in fact they caused a MySQL error that took me a while
to debug). But it is all working perfectly now and the 'customers'[1] are
delighted.

So thanks again to the group and especially Denis.

1. in fact I'm doing it for the love of it, for my choir.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Question about binary transfers in POST requests
Next Topic: file_put_contents not creating file
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Nov 25 02:02:45 GMT 2024

Total time taken to generate the page: 0.05300 seconds