Break results into rows

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

Break results into rows

Post by melomonk »

Hello

I'm truly a newbie - so be gentle

I'm having trouble getting returned results to display as one row per line
Can someone please show me - tell me - advise me - what i'm not doing to get one row per line
Here are the returned results
http://www.openrealtour.com/test/newfile4.php

Here is the code i'm using

Code: Select all

$rs = mysql_query("SELECT tourid, mls, userid, mls_loc FROM tour") or die ("invalid query");
while ($row = mysql_fetch_assoc($rs)) {
    printf("tourid: %s  mls: %s", "http://URL?=" . $row["tourid"], $row["mls"]);
}
mysql_free_result($rs);
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Re: Break results into rows

Post by Skara »

1) Output of php is by default html, so you need to add <br /> at the end of your printf.
or
2) If you want this to output as plaintext, add
header('ContentType: text/plain');
to the top of the file and add \n to the end of the printf.
melomonk
Forum Newbie
Posts: 10
Joined: Thu Jul 09, 2009 10:28 pm

Re: Break results into rows

Post by melomonk »

Thank so much Skara
I appreciate your input - IT HELPED!

I used:

Code: Select all

while ($row = mysql_fetch_assoc($rs)) {
 
    printf("tourid: %s  mls: %s", "http://URL?=" . $row["tourid"], $row["mls"]);
    echo "</br>";
}
and got the desired results
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Re: Break results into rows

Post by Skara »

uh.. it's <br />. There's a space between the r and the / too, btw.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Break results into rows

Post by McInfo »

Skara wrote:2) If you want this to output as plaintext, add
header('ContentType: text/plain');
to the top of the file and add \n to the end of the printf.

Code: Select all

header('Content-Type: text/plain');
//             ^
Edit: This post was recovered from search engine cache.
Post Reply