-
Aug 28, 2003, 06:30 PM
#1
PHP Basics
I am not a programmer, however I can read code. ironic eh? What it the newline character in php. I am just trying to read stuff from a table in a database, the information is retrieve but I need a new line after each row. Code enclosed. How can I put in a newline character in the higlighted line?
<?php
mysql_connect("localhost", "root", "new-password" or
die("Could not connect: " . mysql_error());
mysql_select_db("trial"
$result = mysql_query("SELECT id, FirstNames FROM tbl_name"
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf ("ID: %s Name: %s", $row{0}, $row[1]);
}
mysql_free_result($result);
?>
The curly brakets shoud actually be suare brackets, but I think it is being resloved as an attribute on this site. Please substitute, if you noticed I had to modify this post.
-
Aug 29, 2003, 09:07 AM
#2
Re:PHP Basics
"\n" on unix/linux, "\r\n" on windows.
-
Aug 29, 2003, 10:19 AM
#3
Re:PHP Basics
By the Way....In Perl there is the chomp function that takes the variable and strips the newline character from it-entered from the user <STDIN>.
Example:
$variable1=test;
chomp($variable1)
-
Aug 29, 2003, 10:20 AM
#4
Re:PHP Basics
Is there an equivalent in PHP ?
-
Aug 29, 2003, 11:29 AM
#5
Re:PHP Basics
Not to my knowledge, but it should be fairly easy to write one.
<?
$i=0;
while ($i <= strlen($someString))
{
$cur = substr($someString, $i, 1);
if ($cur == "\n" $cur = "";
$newString= $newString . $cur;
$i++;
}
?>
-
Aug 29, 2003, 01:58 PM
#6
Re:PHP Basics
My webserver is running on Redhat Linux 9.0. I tried the \n but it made no difference.
I used <br>\n instead, it worked fine.
printf ("ID: %s Name: <br>\n"%s", $row{0}, $row[1]);
I wonder what is for the tab character?
-
Aug 29, 2003, 02:52 PM
#7
Re:PHP Basics
Now I see. What you wanted was a break in HTML output. If that's the case then all you need is the "<BR>". "\n" is used for console and file output, not for output to web pages.
For tab you may have to use multiple "nbsp;" 'cause I can't think of a TAB character for HTML. I suggest you use tables though.
-
Re:PHP Basics
Yes, I agree with CKnight, don't try to use tabs it will throw out your layout. Use tables.
-
Re:PHP Basics
I really didn't stop to see what you were attempting. So excuse me if this is of no value to you.
The nl2br function can convert newlines to <br> html tags.
http://us4.php.net/manual/en/function.nl2br.php
I know this will help someone.
-
Sep 1, 2003, 03:12 PM
#10
Re:PHP Basics
you could use tabs in the pre tag
<pre> This is an example that &nb sp; uses tabs &nb sp;
&n bsp;within
those &nb sp; handy pre tags</pre>
As a general rule this probably isn't what you want though.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules