Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #11062
| Path | csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Derek Turner <frderek@cesmail.net> |
| Newsgroups | comp.lang.php |
| Subject | Re: Will this work? [SOLVED] |
| Date | 10 Feb 2011 17:05:53 GMT |
| Lines | 41 |
| Message-ID | <8rik7hFqbhU1@mid.individual.net> (permalink) |
| References | <8rbc1jFh6iU2@mid.individual.net> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| X-Trace | individual.net /KdRkErQSw4AhPm01opdbg4Dz2GIx+UhqtIaLFTXyPveM4ZHA7 |
| Cancel-Lock | sha1:TqcAJrsNo2/7OY+tZTaMLA1bb6I= |
| User-Agent | Pan/0.133 (House of Butterflies) |
| Xref | csiph.com comp.lang.php:11062 |
Show key headers only | 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
Re: Will this work? [SOLVED] Derek Turner <frderek@cesmail.net> - 2011-02-10 17:05 +0000
csiph-web