• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

PHP Question

<?
while ($row = mysql_fetch_object ($sql)) {
echo "<h3 id='news' title='News'>";
echo $row->title;
print "</h3>";
print "<p>";
echo $row->content;
print "</p>";
}

mysql_free_result ($sql);
?>

When I do that, there's an extra line break before the <h3>news</h3>. Why is this? Is there a better way to pull this SQL information?
 
problem most likely lies with the margins between the p of the last entry and the h3 of the next... i don't think this is a php problem, check your style sheets and try adjusting margins accordingly.
 
Any specific reason you have <p></p> around the content and not the <h3></h> part?

Depending on the browser you use, doesn't <p></p> cause some extra line breaks to break it up into paragraphs? If you just want your data to list out one row at a time, take out those <p> and </p> tags and just put in a <BR> in place of both tags.
 
Using the same tags, but in HTML gives me the desired effect. I'm pulling the title into <h3></h3> and the content into <p></p>. You can see here. The "The Idea" header is on the first line, but here, with the php, "News" is on the second line.

Originally posted by: Cheetah8799
Any specific reason you have <p></p> around the content and not the <h3></h> part?

I missed that. Thanks.

Fixed it, but that wasn't the problem. 🙁
 
you're retreiving an empty row on the frist time around. examine the html source of the php one and you'll see:
<div>
<p></p><h3 id="news" title="News"></h3><p></p><h3 id="news" title="News">News</h3>Welcom...
You can either fix this with and empty() check on the row before printing anything out or seeing if you have an empy row in your table. I would do both actually.
 
Originally posted by: fs5
you're retreiving an empty row on the frist time around. examine the html source of the php one and you'll see:
<div>
<p></p><h3 id="news" title="News"></h3><p></p><h3 id="news" title="News">News</h3>Welcom...
You can either fix this with and empty() check on the row before printing anything out or seeing if you have an empy row in your table. I would do both actually.

Thanks! I'll look into that!

I'm so stupid, you were right. Simply an empty row, can't believe I didn't even check that. 🙁

Thanks a lot!
 
if your goint to print or echo static html or text, why not just do
<p>
<? echo $row->content; ?>
</p>
etc.
 
Originally posted by: wkinney
if your goint to print or echo static html or text, why not just do
<p>
<? echo $row->content; ?>
</p>
etc.

Or taking it a step further...

<p>
<?= $row->content; ?>
</p>
 
<?while ($row = mysql_fetch_object ($sql)) { ?>
<h3 id="news" title="News">
<?=$row->title; ?>
</h3>
<p>
<?=$row->content; ?>
</p>
<?}mysql_free_result ($sql);?>

Better?
 
i don't know about you, but i think the last code is quite ugly and hard to read.
but one thing i should note is that not all servers support shorthand printing (or whatever the term is)

that means:
<?=$row->title;?>

may print the contents of $row->title on one server, but may not do that on another if the ability to parse <?= is turned off.

similarly, not all servers understand that <? .... ?> are php delimiters. It's always safer to use <?php ... ?>

In any case, what you have on the first post is fine (with the exception of maybe changing <? to <?php to ensure compatibility).
Mixing plain text (or plain html) is not a good thing to do especially if it involves nesting of commands. It may look simple and nice for now, but when you're back to reviewing your code months later, you'll simply confuse yourself while trying to decode what it was you were doing.

but then again, it all goes back to personal preferences.
 
Thanks for the input. At this time, the two servers I use support the tags I use. I expect it to remain that way, but if it does change in the future, I can always change it.
 
Problems just keep rolling in.

Added an admin panel, had it working fine but some things were messed up. Fixed the code, but now, for some damn reason, my stylesheet is being echo'd before my admin page, after I log in.

Here's a link to the source of that page : Text

Anyone see a problem?
 
Hmmm... couldn't see the problem from the code you posted.
From my wild guess, it might have something to do with the contents of 'includes/head.php' as it is the first thing included on top of the page.

do you have a sample or screenshot of how the problem looks like for comparison, since we have no idea how it look different?


anyways, hope you don't mind with a few more comments on the code you wrote:

1. $HTTP_SERVER_VARS is deprecated and should not be used anymore. instead, use $_SERVER
2. similarly, for session variables, use $_SESSION

3. you don't need to register or unregister any session variables. simply assign a value to the session variable (eg: $_SESSION['username'] = 'stndn') and it will be registered. also, unsetting the variable (eg: unset ($_SESSION['username'])) will unregister the session variable for you

4. Try to put the { ... } braces even on one-liner if() statements for easier reading and debugging purpose
 
Thanks for the help, but I've written my own code this time and it's working pretty damn good. The site's performing exactly as I'd like it to. 🙂
 
Back
Top