myfriend myfriend - 2 years ago 96
PHP Question

Session start in Joomla using a while loop

I have 2 databases, one with Joomla installed and the other with my personal data.

I need to work contemporaneously with these 2 databases.

Now I do a

into my DB with this query:

$query="Select * From lista where user_id='$id'";
$result = mysql_query($query) or die(mysql_error());
ECHO '<P>Modifica <a href="..../test/index.php/modifica">'.$row['struttura'].'</P>';
$session =& JFactory::getSession();
$session->set( 'myvar', $ID_STRUCTURE );

When I go on the page
I use this code:

$session =& JFactory::getSession();
$myvar= $session->get('myvar');
echo $myvar;

I must obtain only the
of the correspondent

If I use an array in the
and a
in the other page
, I obtain all the values.

How can I fix it?

Answer Source

Of course, because you are always overwrite that in your loop. You need to create an array, or make the key to be unique.

while ($row = mysqli_fetch_array($result)) {
    $ID_STRUCTURE = $row['ID'];
    ECHO '<P>Modifica <a href="..../test/index.php/modifica">' . $row['struttura'] . '</P>';
    $myvarArray[] = $ID_STRUCTURE;
$session = & JFactory::getSession();
$session->set('myvar', $myvarArray);

Use mysqli or PDO instead mysql functions since they are deprecated.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download