Jick
04-08-2004, 06:14 PM
Hey all...
I have a new question for whoever can help me. Ok, I'll cut right to the chase. I have a script which I will post below that connects to my database and retrieves all the rows of a specified table. Just to make this easier I will tell you what the script is intended for. This script gets announcements that I insert into the db by means of another page. I have no problem actually with any of the connecting or retrieving the info but I do have a problem with displaying it. I have been using br's to seperate each announcement down the page. I have it automaticly inserting br's into each announcement and then it all is outputed to the page. I have recently noticed that because of the way I'm doing it there is a gap left in the bottom of the last announcement because of the br's. I was told that if I could get the entire results (including the br's) into a var then I could use the function in php to cut the br's off the end of the last announcement getting rid of that annoying gap. My problem is that I don't know how I would get all the results into a var. Here is my script:<?php
mysql_connect("mysqlhost","mysqluser","mysqlpass");
mysql_select_db("mysqldb");
$result = mysql_query("SELECT * FROM news ORDER BY date DESC");
while($r = mysql_fetch_array($result))
{
$id = $r["id"]; $title = $r["title"]; $date = $r["date"]; $body = $r["body"];
echo "<b>$title</b> - <i>$date</i><br />$body<br /><br />\n";
}
?>Just so I don't get info I already have I will also post another version that I tried that didn't work:<?php
mysql_connect("mysqlhost","mysqluser","mysqlpass");
mysql_select_db("mysqldb");
$result = mysql_query("SELECT * FROM news ORDER BY date DESC");
while($r = mysql_fetch_array($result))
{
$id = $r["id"]; $title = $r["title"]; $date = $r["date"]; $body = $r["body"];
$var = "<b>$title</b> - <i>$date</i><br />$body<br /><br />\n";
$var = substr($var, 0, -12);
echo $var;
}
?>It didn't work because that way it was stripping the chars off of every row from the db which I don't want. I just want it to strip the chars from all of the rows as a whole. The reason I want to strip the chars from the very end is because that way it will remove the last couple br's thus removing the gap problem. I will be very greatful if someone can help me. :D
P.S. This is happining on my page (http://jick.zacknetwork.net/index.php) at the bottom where the announcements are displayed.
I have a new question for whoever can help me. Ok, I'll cut right to the chase. I have a script which I will post below that connects to my database and retrieves all the rows of a specified table. Just to make this easier I will tell you what the script is intended for. This script gets announcements that I insert into the db by means of another page. I have no problem actually with any of the connecting or retrieving the info but I do have a problem with displaying it. I have been using br's to seperate each announcement down the page. I have it automaticly inserting br's into each announcement and then it all is outputed to the page. I have recently noticed that because of the way I'm doing it there is a gap left in the bottom of the last announcement because of the br's. I was told that if I could get the entire results (including the br's) into a var then I could use the function in php to cut the br's off the end of the last announcement getting rid of that annoying gap. My problem is that I don't know how I would get all the results into a var. Here is my script:<?php
mysql_connect("mysqlhost","mysqluser","mysqlpass");
mysql_select_db("mysqldb");
$result = mysql_query("SELECT * FROM news ORDER BY date DESC");
while($r = mysql_fetch_array($result))
{
$id = $r["id"]; $title = $r["title"]; $date = $r["date"]; $body = $r["body"];
echo "<b>$title</b> - <i>$date</i><br />$body<br /><br />\n";
}
?>Just so I don't get info I already have I will also post another version that I tried that didn't work:<?php
mysql_connect("mysqlhost","mysqluser","mysqlpass");
mysql_select_db("mysqldb");
$result = mysql_query("SELECT * FROM news ORDER BY date DESC");
while($r = mysql_fetch_array($result))
{
$id = $r["id"]; $title = $r["title"]; $date = $r["date"]; $body = $r["body"];
$var = "<b>$title</b> - <i>$date</i><br />$body<br /><br />\n";
$var = substr($var, 0, -12);
echo $var;
}
?>It didn't work because that way it was stripping the chars off of every row from the db which I don't want. I just want it to strip the chars from all of the rows as a whole. The reason I want to strip the chars from the very end is because that way it will remove the last couple br's thus removing the gap problem. I will be very greatful if someone can help me. :D
P.S. This is happining on my page (http://jick.zacknetwork.net/index.php) at the bottom where the announcements are displayed.