Page 1 of 1

Beginner question

Posted: Fri Apr 14, 2006 2:15 pm
by Cicerius
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello,

I am making a website which makes use of PHP and MySQL and have run into a problem. I use the script below to get information from a database, and between each piece of information (".$row[line_one].") I want to put a line of HTML code, also from the database (".$row[line_two]."). The problem is that I don't want this bit of code after the last piece of information, so I'm wondering if there is a way to get something like the following to display:

Code: Select all

<p>".$row[line_one]."</p>
<p>".$row[line_two]."</p>

<p>".$row[line_one]."</p>
<p>".$row[line_two]."</p>

<p>".$row[line_one]."</p>
<p>".$row[line_two]."</p>

<p>".$row[line_one]."</p>
I am very inexperienced when it comes to PHP, and I'm sorry if this makes no sense, but I would be very grateful for any suggestions!

Here is the script I'm using:

--------------------

Code: Select all

<?php

...

mysql_connect($host,$username,$password) or die("Unable to connect to database");

@mysql_select_db("$database") or die ("Unable to select database $database");

$sqlquery = "SELECT * FROM $table";

$result = mysql_query($sqlquery);

while ($row = mysql_fetch_array($result)) {
echo "
            <p>".$row[line_one]."</p>
            <p>".$row[line_two]."</p>
";
}

if (mysql_num_rows($result)<1) {
echo "No Results!";
}

mysql_free_result($result);
?>
--------------------


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Apr 14, 2006 2:32 pm
by feyd
I'd probably use an array for this. After all the records are processed, simply pop the last element off and implode() the final array.