Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #11062

Re: Will this work? [SOLVED]

From Derek Turner <frderek@cesmail.net>
Newsgroups comp.lang.php
Subject Re: Will this work? [SOLVED]
Date 2011-02-10 17:05 +0000
Message-ID <8rik7hFqbhU1@mid.individual.net> (permalink)
References <8rbc1jFh6iU2@mid.individual.net>

Show all headers | View raw


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.

Back to comp.lang.php | Previous | Next | Find similar | Unroll thread


Thread

Re: Will this work? [SOLVED] Derek Turner <frderek@cesmail.net> - 2011-02-10 17:05 +0000

csiph-web