...

View Full Version : PHP Code into PHP Code (if)



emsanator
11-03-2010, 06:42 PM
Hi Guys!

i need help, how can i add php code into php code?

Add code:


<?php echo session->userinfo['id'];?> // This code: User's ID see



<?php

if($session->userinfo['id']== ** HERE ADD **)
echo $notes;
else
echo " - content message - ";

?>

Thanks!

Keleth
11-03-2010, 06:49 PM
I at least have no idea what you mean by "add php code into php code". What are you trying to add where?

emsanator
11-03-2010, 10:22 PM
I at least have no idea what you mean by "add php code into php code". What are you trying to add where?

Hi Keleth thanks for the reply..

** Here Add ** =
i wish code: <?php echo session->userinfo['id'];?>


if($session->userinfo['id']== $session->userinfo['id']) // Not working..

where something is wrong?

MattF
11-03-2010, 10:40 PM
Not working how? That will always return true, btw.

emsanator
11-03-2010, 11:21 PM
Not working how? That will always return true, btw.


<?php $session->userinfo['id']; ?> -> User's ID Show

user to see the contents of their own:



<?php
if($session->userinfo['id']==2)
echo $notes;
else
echo " - no user's details - ";
?>

(sample: user ID 2)
OK! working..

----



<?php
if($session->userinfo['id']==$session->userinfo['id'])
echo $notes;
else
echo " - no user's details - ";
?>

but not work

(i sorry, English is not advanced )

emsanator
11-04-2010, 08:24 AM
PHP Pages: OK
DB Tablo: OK
User Interface: OKbut
user-specific show: No

I want do to:

http://i54.tinypic.com/mhzuxk.jpg

MattF
11-04-2010, 03:36 PM
Without knowing the workings of the rest of your code, just try this:



<?php
if ($session->userinfo['id'])
{
echo $notes;
}
else
{
echo " - no user's details - ";
}
?>



That is assuming that you are setting $session->userinfo['id'] to something like 0 or false if the current user is not logged in. If that does not work, you will need to provide more information regarding your code for further suggestions.

emsanator
11-04-2010, 04:27 PM
Without knowing the workings of the rest of your code, just try this:



<?php
if ($session->userinfo['id'])
{
echo $notes;
}
else
{
echo " - no user's details - ";
}
?>



That is assuming that you are setting $session->userinfo['id'] to something like 0 or false if the current user is not logged in. If that does not work, you will need to provide more information regarding your code for further suggestions.

Thanks for answer..

showed that all the notes..

Other Codes:

notes.php (header codes)


<?php

// Error reporting:
error_reporting(E_ALL^E_NOTICE);

// Removing notes that are older than an hour:
mysql_query("DELETE FROM notes WHERE id>3 AND dt<SUBTIME(NOW(),'0 1:0:0')");

$query = mysql_query("SELECT * FROM notes ORDER BY id DESC");

$notes = '';
$left='';
$top='';
$zindex='';

while($row=mysql_fetch_assoc($query))
{
// The xyz column holds the position and z-index in the form 200x100x10:
list($left,$top,$zindex) = explode('x',$row['xyz']);

$notes.= '
<div class="note '.$row['color'].'" style="left:'.$left.'px;top:'.$top.'px;z-index:'.$zindex.'">
'.htmlspecialchars($row['text']).'
<div class="author">'.htmlspecialchars($row['name']).'</div>
<span class="data">'.$row['note_id'].'</span>
</div>';
}
?>

class_users.php


/**
* User::getUserInfo()
*
* @param mixed $username
* @return
*/
function getUserInfo($username)
{
global $db;
$sql = "SELECT * FROM users WHERE username = '" . $db->escape($username, true)."'";
$result = $db->query($sql);
if (!$username) {
return false;
}

if (mysql_num_rows($result) > 0) {
$row = $db->fetch($result);
return $row;
} else
return null;
}

/**
* User::getUserById()
*
* @param mixed $id
* @return
*/
public function getUserById($id)
{
global $db;
$sql = "SELECT * FROM users WHERE id = '" . (int)$id . "'";
$row = $db->first($sql);

if ($row) {
return $row;
} else
return 0;
}

/**
* User::getUserList()
*
* @return
*/
public function getUserList()
{
global $db;
$sql = "SELECT id, username,email FROM users ORDER BY username";
$row = $db->fetch_all($sql);

if ($row) {
return $row;
} else
return 0;
}


I added the correct codes? :confused:

MattF
11-04-2010, 04:39 PM
Try changing this line in notes.php:



$query = mysql_query("SELECT * FROM notes ORDER BY id DESC");


to:



$query = mysql_query('SELECT * FROM notes WHERE id='.intval($session->userinfo['id']));

emsanator
11-04-2010, 05:03 PM
Try changing this line in notes.php:



$query = mysql_query("SELECT * FROM notes ORDER BY id DESC");


to:



$query = mysql_query('SELECT * FROM notes WHERE id='.intval($session->userinfo['id']));


Excellent!! MattF, Thank you so much!:thumbsup: Now working..

MattF
11-04-2010, 05:34 PM
You're welcome. Glad to hear that sorted it. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum