Jump to content

Calling a function used in many pages..


Fenhopi

Recommended Posts

I have this piece of code:

function newmessage() {
  		box = new LightFace({ 
 			title: 'New message', 
			width: 600,
			height: 400,
  			content: "<form method='post' action='sendmessage.php'>To: <br><input type='text' name='to'><br><br>Subject: <input type='text' size='94' name='subject'><br><br><textarea name='message' rows='13' cols='63'></textarea><br><br><input type='submit' value='Send' name='send'><input name='from' type='hidden' value='<? echo $username; ?>'></form>",
 			buttons: [
				{
					title: 'Close',
					event: function() { this.close(); }
				}
			]
 		});
 		box.open();		
 	}

 

As well as this piece of code:

 $userid = mysql_real_escape_string($_SESSION['userid']);
    //WALLNOT
   $db2 = "SELECT status FROM comments WHERE touser='$username' AND status='0'";
   $db2connect = $database->query($db2);
   
   $status2 = "SELECT status FROM friends2 WHERE user2='$username' and status='0'";
   $test = $database->query($status2);
   
   $statfromdb = "SELECT stat FROM wallposts WHERE person='$username' AND stat='0'";
   $status = $database->query($statfromdb);
   
   $GetStatus = "SELECT byuser, status, dtime FROM commentstatus WHERE status='$Naw'and person='$username' AND byuser!='$username'";
   $ConnectGetStatus = $database->query($GetStatus);
   
   $Getmsg = "SELECT status FROM messages WHERE status='0' AND touser='$username'";
   $ConnectGetmsg = $database->query($Getmsg);

   $row = mysql_fetch_array($test);
   $row2 = mysql_fetch_array($ConnectGetmsg);
   $getrow = mysql_fetch_array($status);
   $getrow2 = mysql_fetch_array($db2connect);
   $StatusComment = mysql_fetch_array($ConnectGetStatus);
   
   		  //Select profile picture
$GetProfilePicture = "SELECT profilepicture FROM users WHERE username='$username'";
$ConnectProfilePicture = $database->query($GetProfilePicture);
$ProfilePicture = mysql_fetch_array($ConnectProfilePicture);
$MyProfilePicture = $ProfilePicture['profilepicture'];

 

That I use in 19 different pages, is there anyway I can put them all into one page, and just them through a function?

 

It takes so much time when loading if I have it on each page?

 

And if you have any other tips how to optimize my loading speed please write them.

 

Thank you in advance!

 

*Edit: Bad grammar.

Link to comment
Share on other sites

I can't get it to work when I include this piece:

$userid = mysql_real_escape_string($_SESSION['userid']);
    //WALLNOT
   $db2 = "SELECT status FROM comments WHERE touser='$username' AND status='0'";
   $db2connect = $database->query($db2);
   
   $status2 = "SELECT status FROM friends2 WHERE user2='$username' and status='0'";
   $test = $database->query($status2);
   
   $statfromdb = "SELECT stat FROM wallposts WHERE person='$username' AND stat='0'";
   $status = $database->query($statfromdb);
   
   $GetStatus = "SELECT byuser, status, dtime FROM commentstatus WHERE status='$Naw'and person='$username' AND byuser!='$username'";
   $ConnectGetStatus = $database->query($GetStatus);
   
   $Getmsg = "SELECT status FROM messages WHERE status='0' AND touser='$username'";
   $ConnectGetmsg = $database->query($Getmsg);

   $row = mysql_fetch_array($test);
   $row2 = mysql_fetch_array($ConnectGetmsg);
   $getrow = mysql_fetch_array($status);
   $getrow2 = mysql_fetch_array($db2connect);
   $StatusComment = mysql_fetch_array($ConnectGetStatus);
   
           //Select profile picture
   $GetProfilePicture = "SELECT profilepicture FROM users WHERE username='$username'";
   $ConnectProfilePicture = $database->query($GetProfilePicture);
   $ProfilePicture = mysql_fetch_array($ConnectProfilePicture);
   $MyProfilePicture = $ProfilePicture['profilepicture'];

 

I think it might have something to do with session.php.

It says can't re-define db..

Link to comment
Share on other sites

I can't get it to work ... I think it might have something to do with session.php.

 

Can't get WHAT to work? What session.php?

 

You haven't shown the total code that would be needed to produce/reproduce the problem, what it actually did vs what you expected, what exactly session.php is, or what the whole error message was.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.