name from id?

tnijman 09 Jan, 2009
How do I make the cf_id in the foreach, print the name of a user in this table. The names of the user are of course in 'jos_users'. How do I compare them? I need a table to be shown in my chronoforms, for this I use the following code.

<?php
$user = JFactory::getUser();
// $user->id
$db = JFactory::getDBO();
$query = "SELECT * FROM `jos_chronoforms_gastenlijst` WHERE 1";
$db->setQuery($query);
$rows = $db->loadObjectList();
echo $db->getErrorMsg();
?>
<table width="100%">
<tr style="background-color: #d3d3d3"><td><strong>Naam</strong></td><td><strong>Geboortedatum</strong></td><td><strong>Betaald</strong></td><td><strong>Opmerkingen</strong></td><td><strong>Toegevoegd door</strong></td></tr>
<?php
foreach($rows AS $row) {
echo '<tr>';
echo '<td>'.$row->voornaam.' '.$row->achternaam.'</td>';
echo '<td>'.$row->geboortedatum.'</td>';
echo '<td>'.$row->betaald.'</td>';
echo '<td>'.$row->opmerking.'</td>';
// I need the name here.
echo '</tr>';
}
?>
</table>
Max_admin 09 Jan, 2009
Hi tnijman,

replace
// I need the name here.
by
$user->name;
but why do you use all this code ? if you replace $row->opmerking with opmerking then it should work the same and you dont need this PHP code at the top except the $user statement of course!

regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
tnijman 10 Jan, 2009
I know that part. But I need to get the individual names from another database. With chronoforms every entry is automatically saved with the cf_user_id. I need to compare that to the id's from jos_users and then display the name. In the loop. I have this code in the form so I don't use chronoconnectivity for it.

Thanks for the reply!
Max_admin 10 Jan, 2009
Hi tnijman,

No problems, let me know if you have other problems to solve!

cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
grwestby 11 Jan, 2009
I am curious about this question.
Although I would like to retrieve the user "name" from the "cf_user_id" variable in connectivity. The database has recorded the cf_user_id after the form transferred it from user_id. Even though it is the same number I am having trouble displaying the user "name" in connectivity. Can you please assist?
Thank you very much,
George

This is an awesome tool!
tnijman 12 Jan, 2009
<?php
$db = JFactory::getDBO();
$query = "SELECT id, name, username FROM `jos_users` WHERE id = `{cf_user_id}`";
$db->setQuery($query);
$rows = $db->loadObjectList();
echo $db->getErrorMsg();
?>

<?php
foreach($rows AS $row) {
echo $row->name;
}
?>


This gives me an error.. Any clue? this code is in the body of a chronoconnection.

Error:
Unknown column '63' in 'where clause' SQL=SELECT id, name, username FROM `jos_users` WHERE id = `63`
GreyHead 12 Jan, 2009
Hi tnijman,

I think you need to use straight single quotes ' ' round variables and backticks round column and table names
$query = "SELECT id, name, username FROM `jos_users` WHERE `id` = '{cf_user_id}'";

Bob

PS make the DB call =& too- saves duplicating the object.
$db =& JFactory::getDBO();
tnijman 14 Jan, 2009
Well that solves te error but results in an empty area..
Max_admin 14 Jan, 2009
try this:

<?php
$db =& JFactory::getDBO();
$query = "SELECT id, name, username FROM #__users WHERE id = '".$row->cf_user_id."'";
$db->setQuery($query);
$row = $db->loadObject();
echo $db->getErrorMsg();
echo $row->name;
?>
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
tnijman 19 Jan, 2009
That is what did it I only needed to rename $query to $query2 or something otherwise it only shows the name in chronoconnectivity.

Thanks very much!
This topic is locked and no more replies can be posted.