Zorg Posted June 8, 2006 Share Posted June 8, 2006 I'm sorry this might be pretty basic to you guys. But i need to fix this code by tomorrow and i have no clue how to do it. It was written by somebody else and I'm not very well versed in PHP. It is supposed to pull an article from a database (image and some text i believe) truncate it into a kind of a blog format and print the result to the screen. When I run it though i get an empty screen. If somebody could help I'd really appreciate it<?php// Function to truncate long textfunction ShortenText($text) {// Change to the number of characters you want to display$chars = 1000;$text = $text." ";$text = substr($text,0,$chars);$text = substr($text,0,strrpos($text,' '));$text = $text." <strong>...</strong> ";return $text;}// Function to close all HTML tagsfunction close_tags($string){ // match opened tags if(preg_match_all('/<([a-z]+)[ >]/', $string, $start_tags)) { $start_tags = $start_tags[1]; // match closed tags if(preg_match_all('/<\/([a-z]+)>/', $string, $end_tags)) { $complete_tags = array(); $end_tags = $end_tags[1]; foreach($start_tags as $key => $val) { $posb = array_search($val, $end_tags); if(is_integer($posb)) { unset($end_tags[$posb]); } else { $complete_tags[] = $val; } } } else { $complete_tags = $start_tags; } $complete_tags = array_reverse($complete_tags); for($i = 0; $i < count($complete_tags); $i++) { $string .= '</' . $complete_tags[$i] . '>'; } }// Removes the </img> tag$xhtml_tags = array("</img>", "</hr>", "</br>");$string = str_replace($xhtml_tags, "", $string); return $string;}// Random Featured Author Starts Belowdefine ('HOSTNAME', 'xxxx.xxxxxxx.xxxxxx');define ('USERNAME', 'xxxxxxxxxxxxxxx');define ('PASSWORD', 'xxxxxxxxxxxxxxx');define ('DATABASE_NAME', 'xxxxxxxxxxxxxxxxxxx_xxxxxxx_x');$db = mysql_connect(HOSTNAME, USERNAME, PASSWORD) or die ('I cannot connect to MySQL.');mysql_select_db(DATABASE_NAME);# Enter the Archive URL from your Weblog Config and the blog ID number$archive_url="/content/";$entry_blog_id="1";// The following finds the number of Authors in the database and puts the value in the variable $num_authors$result = mysql_query("SELECT * FROM mt_entry , mt_author , mt_placement WHERE (entry_blog_id=$entry_blog_id) and (entry_status=2) and (author_id=entry_author_id) and (entry_id=placement_entry_id) and (placement_category_id=2)");$num_authors = mysql_num_rows($result);//The following finds the number of Authors in the database and puts the value in the variable $num_authors$result = mysql_query("SELECT * FROM mt_entry , mt_author , mt_placement WHERE (entry_blog_id=$entry_blog_id) and (entry_status=2) and (author_id=entry_author_id) and (entry_id=placement_entry_id) and (placement_category_id=2)");$num_authors = mysql_num_rows($result);$date_seed = date("j");$bol_found = false;do { if ($num_authors > $date_seed) { $date_seed = $date_seed * 2; } } while ($bol_found = false);//unfinished code$query = "SELECTentry_basename ,entry_title,entry_text,entry_text_more,date_format(entry_created_on, '%Y') AS year,date_format(entry_created_on, '%m') AS month,date_format(entry_created_on, '%M %d, %Y') AS readable_date,entry_id, entry_author_id,author_id,placement_category_id,placement_entry_id, author_nameFROM mt_entry , mt_author , mt_placementWHERE (entry_blog_id=$entry_blog_id) and (entry_status=2) and (author_id=entry_author_id) and (entry_id=placement_entry_id) and (placement_category_id=2) ORDER by rand()LIMIT 1";$result = mysql_query($query);while ($row = mysql_fetch_array($result)) {$title = $row['entry_title'];$entry = nl2br($row['entry_text']); // nl2br inserts HTML line breaks$author = $row['author_name'];$permalink_url = $archive_url . "authors_database/" . ($row['entry_basename']) . ".php";$unsanitized_text = '<h1>' . ($row['entry_title']) . '</h1>' . ShortenText(nl2br($row['entry_text']));$read_more_about = '<p><a href="' . $permalink_url . '">More about ' . ($row['entry_title']) . '</a> <strong>»»</strong></p>';}mysql_free_result($result);// Print sanitized text$sanitized_text = close_tags($unsanitized_text);echo $sanitized_text, $read_more_about?> Link to comment https://forums.phpfreaks.com/topic/11459-php-code-with-a-bug/ Share on other sites More sharing options...
Zorg Posted June 8, 2006 Author Share Posted June 8, 2006 Ugh I'm going nuts. I've located some code that repeats itself but I don't think that's causing the problem. There is a tag that says unfinished code so I'm assuming something there is off. Link to comment https://forums.phpfreaks.com/topic/11459-php-code-with-a-bug/#findComment-43055 Share on other sites More sharing options...
fert Posted June 8, 2006 Share Posted June 8, 2006 [code]$text = $text." ";$text = substr($text,0,$chars);$text = substr($text,0,strrpos($text,' '));$text = $text." <strong>...</strong> ";[/code]You use $text as a varible in the function twice Link to comment https://forums.phpfreaks.com/topic/11459-php-code-with-a-bug/#findComment-43058 Share on other sites More sharing options...
Zorg Posted June 8, 2006 Author Share Posted June 8, 2006 [!--quoteo(post=381265:date=Jun 7 2006, 11:35 PM:name=phpuesr1)--][div class=\'quotetop\']QUOTE(phpuesr1 @ Jun 7 2006, 11:35 PM) [snapback]381265[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]$text = $text." ";$text = substr($text,0,$chars);$text = substr($text,0,strrpos($text,' '));$text = $text." <strong>...</strong> ";[/code]You use $text as a varible in the function twice[/quote]Would that not make it display the result though. I know zilch about php [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /] , which line should i change. Link to comment https://forums.phpfreaks.com/topic/11459-php-code-with-a-bug/#findComment-43059 Share on other sites More sharing options...
fert Posted June 8, 2006 Share Posted June 8, 2006 [!--quoteo(post=381266:date=Jun 7 2006, 09:44 PM:name=Zorg)--][div class=\'quotetop\']QUOTE(Zorg @ Jun 7 2006, 09:44 PM) [snapback]381266[/snapback][/div][div class=\'quotemain\'][!--quotec--]Would that not make it display the result though. I know zilch about php [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /] , which line should i change.[/quote]Well you should just change the name of $text to like $Text, That might fix the problem [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] Link to comment https://forums.phpfreaks.com/topic/11459-php-code-with-a-bug/#findComment-43061 Share on other sites More sharing options...
Zorg Posted June 8, 2006 Author Share Posted June 8, 2006 [!--quoteo(post=381268:date=Jun 7 2006, 11:46 PM:name=phpuesr1)--][div class=\'quotetop\']QUOTE(phpuesr1 @ Jun 7 2006, 11:46 PM) [snapback]381268[/snapback][/div][div class=\'quotemain\'][!--quotec--]Well you should just change the name of $text to like $Text, That might fix the problem [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /][/quote]Hmm no that doesn't do anything.. I've actually found that script elsewhere on the internet and it is exactly the same as the one I have so I think that should be right. Thanks though Link to comment https://forums.phpfreaks.com/topic/11459-php-code-with-a-bug/#findComment-43062 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.