Results 1 to 5 of 5

Thread: Tranferring PHP Code

  1. #1
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default Tranferring PHP Code

    Hey all...

    As I've expressed before, I don't deal with PHP too much so I can't understand what I'm doing wrong here.

    I have a PHP page (that someone else coded) and I'm trying to integrate it with my design.

    I thought I was doing it right but I must have messed something up along the way.

    Could someone please take a look and let me know where I'm a bit off.

    I'm basically trying to transplant the "Recent Posts" bit.

    Original PHP Page (w/ Coding)
    New PHP Page (w/ Design)


    Also, on an unrelated issue...
    does anyone have any idea what "No Posts to Display" is showing up above the Recent Posts bit.

    Thank you so much!
    Last edited by Medyman; 05-28-2007 at 10:32 PM. Reason: fixed url

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Update: I actually figured out the transplanting part...

    But the "No Posts to Display" issue...

    any ideas?

  3. #3
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Well; it could be anything from an echo in the wrong spot (outside of an conditional statement), to a variable not being defined correctly, and the list goes on. Without the code to look at (the PHP source with any username/passwords taken out), there's not much more I could tell you.

    Hope this helps nonetheless.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  4. #4
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Ok...well not sure which one the trouble is with.

    There are two php codes being called in there

    Recent Posts PHP:
    Code:
    <?
    $blogurl = "http://www.demos.designsbyvishal.com/thepaperbagwriter";
    	
    $conn[] = mysql_connect("xx","xx","xx");
    $conn[] = mysql_connect("xx","xx","xx");
    $conn[] = mysql_connect("xx","xx","xx");
    
    $result[] = mysql_query("select * from xx.wp1_posts where post_status='publish' AND post_type='post' order by post_date DESC LIMIT 0,10",$conn[0]);
    $result[] = mysql_query("select * from xx.blog2_posts where post_status='publish' AND post_type='post' order by post_date DESC LIMIT 0,10",$conn[0]);
    $result[] = mysql_query("select * from xx.wp1_posts where post_status='publish' AND post_type='post' order by post_date DESC LIMIT 0,10",$conn[1]);
    $result[] = mysql_query("select * from xx.blog4_posts where post_status='publish' AND post_type='post' order by post_date DESC LIMIT 0,10",$conn[1]);
    $result[] = mysql_query("select * from xx.blog5_posts where post_status='publish' AND post_type='post' order by post_date DESC LIMIT 0,10",$conn[2]);
    $result[] = mysql_query("select * from xx.wp2_posts where post_status='publish' AND post_type='post' order by post_date DESC LIMIT 0,10",$conn[2]);
    
    mysql_close($conn[0]);
    mysql_close($conn[1]);
    mysql_close($conn[2]);
    
    mysql_connect("xx","xx","xx");
    mysql_select_db("xx");
    
    mysql_query("drop table temp_posts");
    mysql_query("create table temp_posts(id bigint(20) unsigned NOT NULL auto_increment,pid bigint(20) NOT NULL,blogid int(2) NOT NULL,post_date datetime NOT NULL,post_title text NOT NULL,post_content longtext,PRIMARY KEY(ID))");
    
    
    for($i=0;$i<5;$i++){
    	while($row = mysql_fetch_array($result[$i])){
    		$sql = "insert into temp_posts(pid,blogid,post_date,post_title,post_content) values(".$row[ID].",".($i+1).",'".$row[post_date]."','".$row[post_title]."','".$row[post_content]."')";
    		//echo $sql.";<br>";
    		mysql_query($sql);
    	}
    }
    
    
    //$res = search($search,$limit,$page)
    $sql = "select * from temp_posts order by post_date DESC LIMIT 0,10";
    $res = mysql_query($sql);
    
    /*echo ("<h2>Recent Posts</h2>");
    
    while($row = mysql_fetch_array($res)){
    	// use if $row[guid]
    	echo "<a href=$blogurl/".$row[blogid]."/?p=".$row[pid].">".$row[post_title]."</a><br>";
    	echo parsecontent($row[post_content])."<br><br>";
    }*/
    
    function parsecontent($text){
    	$offset = 400;
    	$ext = " [...]";
    	$patterns = "/\<(.*?)\>/";
    	$replacements = "";
    	$newText = preg_replace($patterns,$replacements, $text);
    	if(strlen($newText)<400){
    		$offset = strlen($newText);
    		$ext = "";
    	}
    	$pos = strpos($newText ," ", $offset);
    	if(!$pos)
    		$pos = 400;
    	return substr($newText,0,$pos).$ext;
    }
    ?>
    Search Form:
    Code:
    <?
    /*<form method="get">
    <input type="text" name="s" />
    <input type="submit" value="Search" />
    </form>*/
    if(isset($_GET[s]) && $_GET[s]!=""){
    	$search=$_GET[s];
    	$limit = 10;
    	$page = 1;
    	$blogurl = "http://www.demos.designsbyvishal.com/thepaperbagwriter";
    	
    	
    	$conn[] = mysql_connect("xx","xx","xx");
    	$conn[] = mysql_connect("xx","xx","xx");
    	$conn[] = mysql_connect("xx","xx","xx");
    	
    	/*
    	$conn = mysql_connect("xx","xx","xx");
    	mysql_select_db("xx");
    	*/
    	//$result[] = mysql_query("select *,display_name from xx.wp1_posts,xx.wp1_users where post_title LIKE '&#37;".$search."%' OR post_content LIKE '%".$search."%'",$conn[0]);
    	$result[] = mysql_query("select * from xx.wp1_posts where post_status='publish' AND post_type='post' AND (post_title LIKE '%".$search."%' OR post_content LIKE '%".$search."%')",$conn[0]);
    	$result[] = mysql_query("select * from xx.blog2_posts where post_status='publish' AND post_type='post' AND  (post_title LIKE '%".$search."%' OR post_content LIKE '%".$search."%')",$conn[0]);
    	$result[] = mysql_query("select * from xx.wp1_posts where post_status='publish' AND post_type='post' AND (post_title LIKE '%".$search."%' OR post_content LIKE '%".$search."%')",$conn[1]);
    	$result[] = mysql_query("select * from xx.blog4_posts where post_status='publish' AND post_type='post' AND (post_title LIKE '%".$search."%' OR post_content LIKE '%".$search."%')",$conn[1]);
    	$result[] = mysql_query("select * from xx.blog5_posts where post_status='publish' AND post_type='post' AND (post_title LIKE '%".$search."%' OR post_content LIKE '%".$search."%')",$conn[2]);
    	$result[] = mysql_query("select * from xx.wp2_posts where post_status='publish' AND post_type='post' AND (post_title LIKE '%".$search."%' OR post_content LIKE '%".$search."%')",$conn[2]);
    	
    	mysql_close($conn[0]);
    	mysql_close($conn[1]);
    	mysql_close($conn[2]);
    	
    	$fail = true;
    	for($i=0;$i<5;$i++){
    		if(mysql_num_rows($result[$i]))
    		{
    			$fail=false;
    			break;
    		}
    	}
    	//if($fail){
    	//echo("<h2>No Results Mached your search</h2>");
    	//exit;
    	//}
    	if(!$fail)
    	{
    
    	
    	mysql_connect("xx","xx","xx");
    	mysql_select_db("xx");
    	
    	mysql_query("drop table temp_posts");
    	mysql_query("create table temp_posts(id bigint(20) unsigned NOT NULL auto_increment,pid bigint(20) NOT NULL,blogid int(2) NOT NULL,post_date datetime NOT NULL,post_title text NOT NULL,post_content longtext,PRIMARY KEY(ID))");
    	
    	
    	for($i=0;$i<5;$i++){
    		while($row = mysql_fetch_array($result[$i])){
    			$sql = "insert into temp_posts(pid,blogid,post_date,post_title,post_content) values(".$row[ID].",".($i+1).",'".$row[post_date]."','".$row[post_title]."','".$row[post_content]."')";
    			//echo $sql.";<br>";
    			mysql_query($sql);
    			$result[$i] = NULL;
    		}
    	}
    	
    	
    	//$res = search($search,$limit,$page)
    	$sql = "select * from temp_posts order by post_date LIMIT ".$limit*($page-1).",".$limit;
    	$res = mysql_query($sql);
    		
    	/*while($row = mysql_fetch_array($res)){
    		// use if $row[guid]
    		echo "<a href=$blogurl/".$row[blogid]."/?p=".$row[pid].">".$row[post_title]."</a><br>";
    		echo parsecontent($row[post_content])."<br><br>";
    	}*/
    	}
    }
    
    	
    function parsecontent($text){
    	$offset = 400;
    	$ext = " [...]";
    	$patterns = "/\<(.*?)\>/";
    	$replacements = "";
    	$newText = preg_replace($patterns,$replacements, $text);
    	if(strlen($newText)<400){
    		$offset = strlen($newText);
    		$ext = "";
    	}
    	$pos = strpos($newText ," ", $offset);
    	if(!$pos)
    		$pos = 400;
    	return substr($newText,0,$pos).$ext;
    }
    ?>

  5. #5
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Issue resolved. Thanks anyway guys!

    Normally, I'd share what the issue was and how to fix it. But I didn't do it myself so I can't.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •