PDA

View Full Version : Tranferring PHP Code



Medyman
05-28-2007, 09:31 PM
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) (www.demos.designsbyvishal.com/thepaperbagwriter/home.php)
New PHP Page (w/ Design) (www.demos.designsbyvishal.com/thepaperbagwriter/home3.php)


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!

Medyman
05-28-2007, 09:37 PM
Update: I actually figured out the transplanting part...

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

any ideas?

thetestingsite
05-28-2007, 09:52 PM
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.

Medyman
05-28-2007, 10:43 PM
Ok...well not sure which one the trouble is with.

There are two php codes being called in there

Recent Posts PHP:


<?
$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:


<?
/*<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;
}
?>

Medyman
05-29-2007, 03:31 PM
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.