Re: is there a problem with php script pulling HTML out of database as it writes the page??

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Yes, here's the code that is retrieving "news items" from the database and printing them on the page (I do some other stuff with the text before, and after, I print it, for example, find the sentences, so I can print complete sentences, and not just pieces of sentences). As I say, occasionally these news items contain some HTML, e.g., the <img src="xxxxxxx"> statement. All of the text is being correctly retrieved from the database and written to the page, including the <img src="xxxxxxx"> statement, because I see it all in the page source of the page in my browser. However, the <img src="xxxxxxxx"> statement is NOT working, that is, the image does NOT appear on the page.

$result = mysql_query("SELECT * FROM newsitem ORDER BY newsitem_date DESC");
    if (mysql_num_rows($result) > 0)
    {
     $i = 1;
     while (($row = mysql_fetch_assoc($result)) && ($i < 6)) { ?>
      <div id="newsitem">
<p><?php echo $row['newsitem_date']; ?><b><i><br /> <?php $title = $row['title']; echo $title; echo "</i></b><br> by "; ?> <?php echo $row['author']; echo " of <em>"; echo $row['newsservice']; ?></em><br><br />
      <?php $newsitem_array = explode('.', $row['newsitem_text']);
     $print_newsitem = $newsitem_array[0] . ".";
     $length_newsitem = strlen($print_newsitem);
     for ($j = 1; $length_newsitem < 250; $j++) {
        $print_newsitem = $print_newsitem . $newsitem_array[$j] . ".";
        $length_newsitem = strlen($print_newsitem);
     }
     echo $print_newsitem;
echo "<br>"; $url_string = "<a href=\"" . $row['url'] . "\"> (read more of this article)</a>"; echo $url_string; $blog_result = mysql_query("SELECT * FROM blog where discussion = \"$title\"");
     if (mysql_num_rows($blog_result) > 0)
            $not = "";
     else
         $not = " not";
echo "<br>"; echo "This news item does$not have a blog discussion "; echo "&nbsp;&nbsp;";
     if (mysql_num_rows($blog_result) > 0)
echo "<a href=\"bloglist.php?discussion=$title\">Read this item's blog</a> ";
     else
echo "<a href=\"blog.php?discussion=$title\">Start a discussion on this item</a> ";
       $i++;
      ?>
      </p><br />
      </div>
    <?php
     }
    }
    ?>

Stut wrote:
On 15 Jul 2008, at 22:36, Rod Clay wrote:
Hello. Again, I'm fairly new to php so please forgive me if my question is a very simple or obvious one.

I've just tried testing for the first time some php code that is pulling text out of a database to print it on the webpage. Some of this text includes HTML, specifically in this case an <img src="xxxxxxxxx"> statement. Much to my surprise, this is not working. Is there a problem with pulling HTML out of a database like this as the page is being written? There's no problem of course if my php code is writing the HTML to the page - in this case, the <img src="xxxxxx"> statement works fine and the image is displayed. Why is it a problem when my php script pulls the HTML code out of a database and writes it to the page from there??

It would appear that when my php script writes HTML to the page a process of some kind is executed to, in this case, get the image and put it on the page. Apparently this same process is NOT executed if the HTML is retrieved from a database and simply written to the page from there. Is this correct? And, if it is, can anyone suggest a workaround, another way to get done what I'm trying to do here?

Code please, we're not mind readers!

-Stut


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux