Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 14
  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2007
    Messaggi
    225

    estrarre dato da una funzione

    Salve ragazzi! Premetto che sono un pò scarsetto con php. Se ho una funzione simile a questa:

    codice:
    function get_number($a, $b) 
    {
    
    $b = $a + 2;
    
    $X = $b - 7;
    
    $c = $X * 32;
    
    return $c;
    }
    
    $a1 = 20; 
    $b1 = 70;
    
    echo get_number($a1, $b1);
    Se volessi visualizzare anche il risultato di $X come posso fare senza modificare la funzione?

  2. #2
    Utente di HTML.it L'avatar di neroux
    Registrato dal
    Aug 2009
    Messaggi
    1,973
    codice:
    $b1-7;
    non c'è un altro modo

    www.sitemeer.com » Quando un sito pare irraggiungibile

    Se ti piace ci puoi trovare anche su Facebook

  3. #3
    Utente di HTML.it L'avatar di garakkio
    Registrato dal
    Dec 2011
    residenza
    Roma
    Messaggi
    480
    Codice PHP:
    <?php
    echo get_number($a1$b1) / 32;

  4. #4
    Utente di HTML.it L'avatar di neroux
    Registrato dal
    Aug 2009
    Messaggi
    1,973
    Originariamente inviato da neroux
    codice:
    $b1-7;
    non c'è un altro modo
    Dovrebbe essere -5 però l'esempio non è molto chiaro. Dovresti spiegare perché lo vuoi fare.

    www.sitemeer.com » Quando un sito pare irraggiungibile

    Se ti piace ci puoi trovare anche su Facebook

  5. #5
    Utente di HTML.it
    Registrato dal
    Jul 2007
    Messaggi
    225
    Da una query del file "function.php" di phpbb, devo aggiungere un contatore dei post non letti dall'utente. In pratica devo metere accanto a "i tuoi messaggi" il numero dei messaggi non letti, cioè tipo così: "(3)i tuoi messaggi".
    Ho individuato la query, ma si trova dentro una funzione:

    [code]
    function get_unread_topics($user_id = false, $sql_extra = '', $sql_sort = '', $sql_limit = 1001, $sql_limit_offset = 0)
    {
    global $config, $db, $user;

    $user_id = ($user_id === false) ? (int) $user->data['user_id'] : (int) $user_id;

    // Data array we're going to return
    $unread_topics = array();

    if (empty($sql_sort))
    {
    $sql_sort = 'ORDER BY t.topic_last_post_time DESC';
    }

    if ($config['load_db_lastread'] && $user->data['is_registered'])
    {
    // Get list of the unread topics
    $last_mark = (int) $user->data['user_lastmark'];
    //QUESTA E' LA QUERY DOVE DEVO AGGIUNGERE IL CONTATORE E POI ESTRARRE IL RISULTATO FUORI DALLA FUNZIONE
    $sql_array = array(
    'SELECT' => 't.topic_id, t.topic_last_post_time, tt.mark_time as topic_mark_time, ft.mark_time as forum_mark_time',

    'FROM' => array(TOPICS_TABLE => 't'),

    'LEFT_JOIN' => array(
    array(
    'FROM' => array(TOPICS_TRACK_TABLE => 'tt'),
    'ON' => "tt.user_id = $user_id AND t.topic_id = tt.topic_id",
    ),
    array(
    'FROM' => array(FORUMS_TRACK_TABLE => 'ft'),
    'ON' => "ft.user_id = $user_id AND t.forum_id = ft.forum_id",
    ),
    ),

    'WHERE' => "
    t.topic_last_post_time > $last_mark AND
    (
    (tt.mark_time IS NOT NULL AND t.topic_last_post_time > tt.mark_time) OR
    (tt.mark_time IS NULL AND ft.mark_time IS NOT NULL AND t.topic_last_post_time > ft.mark_time) OR
    (tt.mark_time IS NULL AND ft.mark_time IS NULL)
    )
    $sql_extra
    $sql_sort",
    );

    $sql = $db->sql_build_query('SELECT', $sql_array);
    $result = $db->sql_query_limit($sql, $sql_limit, $sql_limit_offset);

    //QUESTO E' QUELLO CHE VORREI INSERIRE (non so se sia giusto)
    $conta = (int) mysql_num_rows($result);


    while ($row = $db->sql_fetchrow($result))
    {
    $topic_id = (int) $row['topic_id'];
    $unread_topics[$topic_id] = ($row['topic_mark_time']) ? (int) $row['topic_mark_time'] : (($row['forum_mark_time']) ? (int) $row['forum_mark_time'] : $last_mark);
    }
    $db->sql_freeresult($result);
    }
    else if ($config['load_anon_lastread'] || $user->data['is_registered'])
    {
    global $tracking_topics;

    if (empty($tracking_topics))
    {
    $tracking_topics = request_var($config['cookie_name'] . '_track', '',

  6. #6
    Utente di HTML.it
    Registrato dal
    Jul 2007
    Messaggi
    225
    Da una query del file "function.php" di phpbb, devo aggiungere un contatore dei post non letti dall'utente. In pratica devo metere accanto a "i tuoi messaggi" il numero dei messaggi non letti, cioè tipo così: "(3)i tuoi messaggi".
    Ho individuato la query, ma si trova dentro una funzione:

    [code]
    function get_unread_topics($user_id = false, $sql_extra = '', $sql_sort = '', $sql_limit = 1001, $sql_limit_offset = 0)
    {
    global $config, $db, $user;

    $user_id = ($user_id === false) ? (int) $user->data['user_id'] : (int) $user_id;

    // Data array we're going to return
    $unread_topics = array();

    if (empty($sql_sort))
    {
    $sql_sort = 'ORDER BY t.topic_last_post_time DESC';
    }

    if ($config['load_db_lastread'] && $user->data['is_registered'])
    {
    // Get list of the unread topics
    $last_mark = (int) $user->data['user_lastmark'];
    //QUESTA E' LA QUERY DOVE DEVO AGGIUNGERE IL CONTATORE E POI ESTRARRE IL RISULTATO FUORI DALLA FUNZIONE
    $sql_array = array(
    'SELECT' => 't.topic_id, t.topic_last_post_time, tt.mark_time as topic_mark_time, ft.mark_time as forum_mark_time',

    'FROM' => array(TOPICS_TABLE => 't'),

    'LEFT_JOIN' => array(
    array(
    'FROM' => array(TOPICS_TRACK_TABLE => 'tt'),
    'ON' => "tt.user_id = $user_id AND t.topic_id = tt.topic_id",
    ),
    array(
    'FROM' => array(FORUMS_TRACK_TABLE => 'ft'),
    'ON' => "ft.user_id = $user_id AND t.forum_id = ft.forum_id",
    ),
    ),

    'WHERE' => "
    t.topic_last_post_time > $last_mark AND
    (
    (tt.mark_time IS NOT NULL AND t.topic_last_post_time > tt.mark_time) OR
    (tt.mark_time IS NULL AND ft.mark_time IS NOT NULL AND t.topic_last_post_time > ft.mark_time) OR
    (tt.mark_time IS NULL AND ft.mark_time IS NULL)
    )
    $sql_extra
    $sql_sort",
    );

    $sql = $db->sql_build_query('SELECT', $sql_array);
    $result = $db->sql_query_limit($sql, $sql_limit, $sql_limit_offset);

    //QUESTO E' QUELLO CHE VORREI INSERIRE (non so se sia giusto)
    $conta = (int) mysql_num_rows($result);


    while ($row = $db->sql_fetchrow($result))
    {
    $topic_id = (int) $row['topic_id'];
    $unread_topics[$topic_id] = ($row['topic_mark_time']) ? (int) $row['topic_mark_time'] : (($row['forum_mark_time']) ? (int) $row['forum_mark_time'] : $last_mark);
    }
    $db->sql_freeresult($result);
    }
    else if ($config['load_anon_lastread'] || $user->data['is_registered'])
    {
    global $tracking_topics;

    if (empty($tracking_topics))
    {
    $tracking_topics = request_var($config['cookie_name'] . '_track', '', false, true);
    $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
    }

    if (!$user->data['is_registered'])
    {
    $user_lastmark = (isset($tracking_topics['l'])) ? base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate'] : 0;
    }
    else
    {
    $user_lastmark = (int) $user->data['user_lastmark'];
    }

    $sql = 'SELECT t.topic_id, t.forum_id, t.topic_last_post_time
    FROM ' . TOPICS_TABLE . ' t
    WHERE t.topic_last_post_time > ' . $user_lastmark . "
    $sql_extra
    $sql_sort";
    $result = $db->sql_query_limit($sql, $sql_limit, $sql_limit_offset);

    while ($row = $db->sql_fetchrow($result))
    {
    $forum_id = (int) $row['forum_id'];
    $topic_id = (int) $row['topic_id'];
    $topic_id36 = base_convert($topic_id, 10, 36);

    if (isset($tracking_topics['t'][$topic_id36]))
    {
    $last_read = base_convert($tracking_topics['t'][$topic_id36], 36, 10) + $config['board_startdate'];

    if ($row['topic_last_post_time'] > $last_read)
    {
    $unread_topics[$topic_id] = $last_read;
    }
    }
    else if (isset($tracking_topics['f'][$forum_id]))
    {
    $mark_time = base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate'];

    if ($row['topic_last_post_time'] > $mark_time)
    {
    $unread_topics[$topic_id] = $mark_time;
    }
    }
    else
    {
    $unread_topics[$topic_i

  7. #7
    Utente di HTML.it
    Registrato dal
    Jul 2007
    Messaggi
    225
    Da una query del file "function.php" di phpbb, devo aggiungere un contatore dei post non letti dall'utente. In pratica devo metere accanto a "i tuoi messaggi" il numero dei messaggi non letti, cioè tipo così: "(3)i tuoi messaggi".
    Ho individuato la query, ma si trova dentro una funzione:

    codice:
    function get_unread_topics($user_id = false, $sql_extra = '', $sql_sort = '', $sql_limit = 1001, $sql_limit_offset = 0)
    {
    	global $config, $db, $user;
    
    	$user_id = ($user_id === false) ? (int) $user->data['user_id'] : (int) $user_id;
    
    	// Data array we're going to return
    	$unread_topics = array();
    
    	if (empty($sql_sort))
    	{
    		$sql_sort = 'ORDER BY t.topic_last_post_time DESC';
    	}
    
    	if ($config['load_db_lastread'] && $user->data['is_registered'])
    	{
    		// Get list of the unread topics
    		$last_mark = (int) $user->data['user_lastmark'];
    //QUESTA E' LA QUERY DOVE DEVO AGGIUNGERE IL CONTATORE E POI ESTRARRE IL RISULTATO FUORI DALLA FUNZIONE
    		$sql_array = array(
    			'SELECT'		=> 't.topic_id, t.topic_last_post_time, tt.mark_time as topic_mark_time, ft.mark_time as forum_mark_time',
    
    			'FROM'			=> array(TOPICS_TABLE => 't'),
    
    			'LEFT_JOIN'		=> array(
    				array(
    					'FROM'	=> array(TOPICS_TRACK_TABLE => 'tt'),
    					'ON'	=> "tt.user_id = $user_id AND t.topic_id = tt.topic_id",
    				),
    				array(
    					'FROM'	=> array(FORUMS_TRACK_TABLE => 'ft'),
    					'ON'	=> "ft.user_id = $user_id AND t.forum_id = ft.forum_id",
    				),
    			),
    
    			'WHERE'			=> "
    				 t.topic_last_post_time > $last_mark AND
    				(
    				(tt.mark_time IS NOT NULL AND t.topic_last_post_time > tt.mark_time) OR
    				(tt.mark_time IS NULL AND ft.mark_time IS NOT NULL AND t.topic_last_post_time > ft.mark_time) OR
    				(tt.mark_time IS NULL AND ft.mark_time IS NULL)
    				)
    				$sql_extra
    				$sql_sort",
    		);
    
    		$sql = $db->sql_build_query('SELECT', $sql_array);
    		$result = $db->sql_query_limit($sql, $sql_limit, $sql_limit_offset);
    
    //QUESTO E' QUELLO CHE VORREI INSERIRE (non so se sia giusto)
    $conta = (int) mysql_num_rows($result);
    
    
    		while ($row = $db->sql_fetchrow($result))
    		{
    			$topic_id = (int) $row['topic_id'];
    			$unread_topics[$topic_id] = ($row['topic_mark_time']) ? (int) $row['topic_mark_time'] : (($row['forum_mark_time']) ? (int) $row['forum_mark_time'] : $last_mark);
    		}
    		$db->sql_freeresult($result);
    	}
    	else if ($config['load_anon_lastread'] || $user->data['is_registered'])
    	{
    		global $tracking_topics;
    
    		if (empty($tracking_topics))
    		{
    			$tracking_topics = request_var($config['cookie_name'] . '_track', '', false, true);
    			$tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
    		}
    
    		if (!$user->data['is_registered'])
    		{
    			$user_lastmark = (isset($tracking_topics['l'])) ? base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate'] : 0;
    		}
    		else
    		{
    			$user_lastmark = (int) $user->data['user_lastmark'];
    		}
    
    		$sql = 'SELECT t.topic_id, t.forum_id, t.topic_last_post_time
    			FROM ' . TOPICS_TABLE . ' t
    			WHERE t.topic_last_post_time > ' . $user_lastmark . "
    			$sql_extra
    			$sql_sort";
    		$result = $db->sql_query_limit($sql, $sql_limit, $sql_limit_offset);
    
    		while ($row = $db->sql_fetchrow($result))
    		{
    			$forum_id = (int) $row['forum_id'];
    			$topic_id = (int) $row['topic_id'];
    			$topic_id36 = base_convert($topic_id, 10, 36);
    
    			if (isset($tracking_topics['t'][$topic_id36]))
    			{
    				$last_read = base_convert($tracking_topics['t'][$topic_id36], 36, 10) + $config['board_startdate'];
    
    				if ($row['topic_last_post_time'] > $last_read)
    				{
    					$unread_topics[$topic_id] = $last_read;
    				}
    			}
    			else if (isset($tracking_topics['f'][$forum_id]))
    			{
    				$mark_time = base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate'];
    
    				if ($row['topic_last_post_time'] > $mark_time)
    				{
    					$unread_topics[$topic_id] = $mark_time;
    				}
    			}
    			else
    			{
    				$unread_topics[$topic_id] = $user_lastmark;
    			}
    		}
    		$db->sql_freeresult($result);
    	}
    
    	return $unread_topics;
    }
    quindi, non c'è un modo, per estrapolare $conta?

  8. #8
    Utente di HTML.it
    Registrato dal
    Jul 2007
    Messaggi
    225
    scusate ragazzi, ho la connessione un pò pazza oggi, mi ha ripetuto il messaggio 3 volte

  9. #9
    Utente di HTML.it L'avatar di garakkio
    Registrato dal
    Dec 2011
    residenza
    Roma
    Messaggi
    480
    Fammi capire, tu hai una funzione che fa una query e ti restituisce un array di topic non letti.
    Vuoi sapere quanti sono i topic non letti e vorresti contare i risultati della query?
    Ti prego, dimmi che ho capito male!

  10. #10
    Utente di HTML.it L'avatar di .Kurt
    Registrato dal
    Jul 2007
    Messaggi
    654
    tipico problema XY

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.