CodeCharge Studio
search Register Login  

Web Reports

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

YesSoftware Forums -> CodeCharge Studio -> PHP

 [Resolved - SQL To PHP ]

Print topic Send  topic

Author Message
CodeChargeMVP

Posts: 473
Posted: 05/06/2011, 1:06 AM

Hi,

I wanna translate this sql instruction to php:

SELECT ObjEstCod,ObjEstDes,CONCAT(SUBSTRING_INDEX(ObjEstDes,' ',10),' ',REPEAT('.',3)) AS ObjEstDes_ FROM objetivo_estrategico ORDER BY ObjEstCod ASC

If there�s any php headz who could help,would be so much appreciate.

Greets.
_________________
Best Regards
Entrepeneur | NT Consultant
View profile  Send private message
mamboBROWN


Posts: 1713
Posted: 05/06/2011, 9:35 AM

CodeChargeMVP,

We need more information. When you say translate sql instruction to php what do you mean? Are you still pulling information from a database? Do you want to create a stored procedure and call it in PHP? We need more details.
View profile  Send private message
CodeChargeMVP

Posts: 473
Posted: 05/09/2011, 3:34 AM

Hi mamboBrown,

What I mean is literaly translate a sql instruction to php, this is, get the same result with php code than the sql instruction used.

But there is still some mistakes on my php code,I´ll back with the solution, what I´m gonna do is first translate it to Javascript where I know how to manage, then get the php code.

Quote mamboBROWN:
CodeChargeMVP,

We need more information. When you say translate sql instruction to php what do you mean? Are you still pulling information from a database? Do you want to create a stored procedure and call it in PHP? We need more details.

_________________
Best Regards
Entrepeneur | NT Consultant
View profile  Send private message
andy


Posts: 183
Posted: 05/09/2011, 2:12 PM

You execute a native sql statement in a server side event like this:

  
global $DBConnection1;  
  
$myvariable = "22";  
  
$sql1 = "UPDATE mytable set myfield = $myvariable WHERE item_id=$recordid";  
$sql2 = "SELECT myfield FROM mytable WHERE anotherfield=$myvariable";  
$db = new clsDBConnection1();  
$db->query($sql1);  
$db->query($sql2);  
  
$db->close();  

The above queries don't do anything meaningful but just shows you how to define your sql query(ies), open a connection, execute it (or them), then close the connection.
Or is this obvious and am I missing the question?
_________________
Andy

RAD tools for rich UI controls:
http://www.koolphptools.com
View profile  Send private message
CodeChargeMVP

Posts: 473
Posted: 05/10/2011, 3:02 AM

hi andy,

I already solved it, I think you missed the question,

The idea was to messure the length of a very long string description field from a grid,

counting the blank spaces between words, and cutting the description on the number 10

blank space and padding thre dots points to the right (that´s what the sql instruction does).

The trick was than on PHP the strings could be handle as arrays, so then is quite easy to find

where is placed the blank space.

Thank you very much indeed for your answer, also to mamboBrown.

Quote andy:
You execute a native sql statement in a server side event like this:

  
global $DBConnection1;  
  
$myvariable = "22";  
  
$sql1 = "UPDATE mytable set myfield = $myvariable WHERE item_id=$recordid";  
$sql2 = "SELECT myfield FROM mytable WHERE anotherfield=$myvariable";  
$db = new clsDBConnection1();  
$db->query($sql1);  
$db->query($sql2);  
  
$db->close();  

The above queries don't do anything meaningful but just shows you how to define your sql query(ies), open a connection, execute it (or them), then close the connection.
Or is this obvious and am I missing the question?

_________________
Best Regards
Entrepeneur | NT Consultant
View profile  Send private message
mamboBROWN


Posts: 1713
Posted: 05/10/2011, 7:42 PM

CodeChargeMVP,

Do you mind sharing your answer with the community?
View profile  Send private message
CodeChargeMVP

Posts: 473
Posted: 05/12/2011, 1:03 AM

Yes sure,

/*SELECT ObjEstCod,ObjEstDes,CONCAT(SUBSTRING_INDEX(ObjEstDes,' ',10),' ',REPEAT('.',3)) AS ObjEstDes_
FROM objetivo_estrategico ORDER BY ObjEstCod ASC*/

$Cadena = $desembolsos1->OEDesc->Value;
$LaPosicion = 0;
$NumPosiciones = 0;
$Posiciones = array();

if($Cadena != "")
{

for($Contador = 0;$Contador<strlen($Cadena);$Contador++)
{
if($Cadena[$Contador] == " "){

$NumPosiciones++;

$LaPosicion = $Contador;

$Posiciones[] = $LaPosicion;
}

}

if($NumPosiciones >= 9)
{
$Cadena = substr($Cadena,0,$Posiciones[9]);

$Cadena = $Cadena . " " . str_repeat(".",3);

$desembolsos1->OEDesc->SetValue($Cadena);

}

}



Quote mamboBROWN:
CodeChargeMVP,

Do you mind sharing your answer with the community?

_________________
Best Regards
Entrepeneur | NT Consultant
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.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


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