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 while
into my DB with this query:
$query="Select * From lista where user_id='$id'";
$result = mysql_query($query) or die(mysql_error());
while($row=mysql_fetch_array($result))
{
$ID_STRUCTURE=$row['ID'];
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 /test/index.php/modifica
I use this code:
$session =& JFactory::getSession();
$myvar= $session->get('myvar');
echo $myvar;
I must obtain only the $ID_STRUCTURE
of the correspondent $row['struttura']
.
If I use an array in the while
and a foreach
in the other page /test/index.php/modifica
, I obtain all the values.
How can I fix it?
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.