repeating the row

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
melomonk
Forum Newbie
Posts: 10
Joined: Thu Jul 09, 2009 10:28 pm

repeating the row

Post by melomonk »

Hello

I'm stuck - blinders welded on I guess - but i can't see what I'm doing wrong :banghead:

I'm trying to achieve one row of returned data per line while concatenating a URL to the first field
I've pasted the code and the error received

Can someone else see what I'm doing wrong? I thought a new pair of eyes would help....

Code: Select all

 
$rs = mysql_query("select blah from blah") or die ("invalid query");
while ($row = mysql_fetch_assoc($rs)) {
    for($i = 0; $i < $row; $i++){
        echo ("field1: %s  field2: %s  field3: %s  field4: %s", "http://URL.php?id=" . $row["field1"], $row["field2"], $row["field3"], $row["field4"] . "\n");
    }
mysql_free_result($rs);
 
Error produced:
Parse error: syntax error, unexpected ',' in newfile3.php
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: repeating the row

Post by califdon »

Did you intend to use sprintf()? You omitted the function name, I think.
melomonk
Forum Newbie
Posts: 10
Joined: Thu Jul 09, 2009 10:28 pm

Re: repeating the row

Post by melomonk »

when i use printf

i get
Parse error: syntax error, unexpected $end in newfile3.php


thanks for looking
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: repeating the row

Post by califdon »

What I'm trying to tell you is that I can't make any sense of your syntax. And printf() is not the same as sprintf(). Look up the syntax, although I don't even see why you would be trying to use those functions. One thing is sure, you can't just make up your own syntax as you go along. You have to follow the syntax in the manual.
melomonk
Forum Newbie
Posts: 10
Joined: Thu Jul 09, 2009 10:28 pm

Re: repeating the row

Post by melomonk »

thanks
i appreciate your time
it's been helpful
melomonk
Forum Newbie
Posts: 10
Joined: Thu Jul 09, 2009 10:28 pm

Re: repeating the row

Post by melomonk »

echo
printf
sprintf

i just need to row to repeat
until all of the data is returned
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: repeating the row

Post by califdon »

echo is the commonly used command to simply send text to the browser. print can also be used, there's very little difference between the two. printf() and sprintf() are functions used to format data and I don't see any reason for you to use them in that context.

The usual practice when using mysql_fetch_assoc() is to use extract() to set variables with the names of each field, making it easy to use them in your script without the clumsy syntax of $row[..].

Code: Select all

while ($row = mysql_fetch_assoc($rs)) {
   extract($row);
   echo "http://URL.php?id=$field1, $field2, $field3, $field4\n";
}
I'm not sure that's exactly what you want, since I can't make heads or tails of your original code, but it looks to me like that's what you were trying to do.
Post Reply