CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 getting values from SQL

Print topic Send  topic

Author Message
bas
Posted: 08/14/2008, 1:26 PM

How do I get to values of variables from a SQL

ie. From the following the two fields I want are - siteip and location
So I tried this:

$db = new clsDBConnection1();
$SQL = "select * from users where user_id = " . $sitename;
$db->query($SQL);
$test1 = $db->siteip->GetValue();
$test2 = $db->location->GetValue();
$db->close();
echo $test1;
echo $test2;


wkempees


Posts: 1679
Posted: 08/14/2008, 1:45 PM

Help File: Retrieve Multiple Field Values from a Database
Quote :
function UserInfo_BeforeShow(& $sender) {
global $UserInfo;

// Read user_id from URL
$UserId = CCGetFromGet("user_id", 0);

if ($UserId > 0) {
// Open connection
$db = new clsDBConnection1();
$SQL = "SELECT emp_name, phone_work FROM employees WHERE emp_id=".$UserId;
$db->query($SQL);
$Result = $db->next_record();
if ($Result) {
$UserName = $db->f("emp_name");
$WorkPhone = $db->f("phone_work");
}
$db->close();

// Show a label value
$UserInfo->SetValue($UserName .", phone: ". $WorkPhone);
} else {
$UserInfo->Visible = False;
}
}


(I do strongly suggest to read the Doc's or Help files)

  
$db = new clsDBConnection1();  
$SQL = "select * from users where user_id = " . $sitename;   
$db->query($SQL);  
$test1 = $db->siteip->GetValue();  
$test2 = $db->location->GetValue();  
$db->close();  
echo $test1;  
echo $test2;  
should be like
  
$db = new clsDBConnection1();  
$SQL = "select siteip, location from users where user_id = " . $db->ToSQL($sitename, ccsText);  
$db->query($SQL);  
$test1 = $db->f("siteip");  
$test2 = $db->f("location");  
$db->close();  
echo $test1;  
echo $test2;  

Note the changes in the "select" !!

Walter


_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
bas
Posted: 08/14/2008, 3:24 PM

Thanks Walter,

I tried that from the help but just couldn't get the test1 etc to pick up
value from the db
I looked at some forum post and modified it a bit.

Can't see where the f("variable name") comes from

Modified the code as you suggest but still when I echo $test1 & $test2 thier
values are blank!



"wkempees" <wkempees@forum.codecharge> wrote in message
news:548a4995353035@news.codecharge.com...
> Help File: Retrieve Multiple Field Values from a Database
>
Quote :
> function UserInfo_BeforeShow(& $sender) {
> global $UserInfo;
>
> // Read user_id from URL
> $UserId = CCGetFromGet("user_id", 0);
>
> if ($UserId > 0) {
> // Open connection
> $db = new clsDBConnection1();
> $SQL = "SELECT emp_name, phone_work FROM employees WHERE
> emp_id=".$UserId;
> $db->query($SQL);
> $Result = $db->next_record();
> if ($Result) {
> $UserName = $db->f("emp_name");
> $WorkPhone = $db->f("phone_work");
> }
> $db->close();
>
> // Show a label value
> $UserInfo->SetValue($UserName .", phone: ". $WorkPhone);
> } else {
> $UserInfo->Visible = False;
> }
> }
>
>
>
> (I do strongly suggest to read the Doc's or Help files)
>
>
  
> $db = new clsDBConnection1();  
> $SQL = "select * from users where user_id = " . $sitename;  
> $db->query($SQL);  
> $test1 = $db->siteip->GetValue();  
> $test2 = $db->location->GetValue();  
> $db->close();  
> echo $test1;  
> echo $test2;  
> 
> should be like
>
  
> $db = new clsDBConnection1();  
> $SQL = "select siteip, location from users where user_id = " .  
> $db->ToSQL($sitename, ccsText);  
> $db->query($SQL);  
> $test1 = $db->f("siteip");  
> $test2 = $db->f("location");  
> $db->close();  
> echo $test1;  
> echo $test2;  
> 
>
> Note the changes in the "select" !!
>
> Walter
>
>
> _________________
> Origin: NL, Timezone GMT+1 (Forumtime +9)
> CCS3/4.01.006 PhP, MySQL (Vista/XP, XAMPP)
>
> if you liked this info PAYPAL me: http://donate.consultair.eu
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

wkempees


Posts: 1679
Posted: 08/14/2008, 3:40 PM

As I said earlier:
is $sitemap a number or text?
Post your entire codeblock here.
If $sitemap is text then you are comparing an integer (user_id) with a textvalue ($sitemap).
if $sitemap is a number then you have to change the SQL into
  
  
$SQL = "select siteip, location from users where user_id = " .   $db->ToSQL($sitename, ccsInteger);    
  

Walter

_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.