How to run .ktr transformations in PHP - php

I developed the following API in PHP / HTML:
I need the result of the select option to serve input to the following ETL transformation:
I used "RJ" as an example in the query. But I need this result to come from the API. What step can I use to recover this data?
Is the reverse process possible? Can I make the result of this transformation available (which is an excel worksheet) for the user to download?
Edit 1: That's how I get the form results. It's a simple PHP code.
<?php
$conexaobd = new ConexaoBD;
$conexao = $conexaobd->conectarAoBD();
$buscar=$_POST['buscar'];
$sql = "SELECT p.id_projeto, p.municipio, p.estado, p.nome FROM projeto p WHERE p.estado LIKE '%".$buscar."%' ORDER BY p.id_projeto";
$resultado_query = mysqli_query($conexao, $sql);
if (!$resultado_query) {
echo "Erro: " . $sql . "<br>" . mysqli_error($conexao);
}
if (!$linha = $resultado_query->fetch_array(MYSQLI_ASSOC)){
echo "<h3>Nenhum registro encontrado.</h3>";
} else {
while($linha = $resultado_query->fetch_array(MYSQLI_ASSOC)){
$id = $linha['id_projeto'];
$municipio = $linha['municipio'];
$estado = $linha['estado'];
$nome = $linha['nome'];
echo "<h2><strong>ID do projeto: </strong>".#$id."</h2>";
echo "<br/>";
echo "<strong>MunicĂ­pio: </strong>".#$municipio;
echo "<br/>";
echo "<strong>Estado: </strong>".#$estado;
echo "<br/>";
echo "<strong>Nome do projeto: </strong>".#$nome;
echo "<br/>";
}
}
?>

Related

How do I pass this information to print it out in another document? PHP MySQL

I am having trouble echoing row data within the page I want to print it out to.
My function works, but only echoes the information because it is local (within the same function).
I'm trying to get this function to echo the database's information to another .php file (same program).
public function findByUsername($username) {
$sql = 'SELECT * FROM events WHERE username=? ';
$statement = DatabaseHelper::runQuery($this->connection, $sql, Array($username));
while ($row = $statement->fetch()) {
echo $row['username'] . "<br />";
echo $row['date'] . "<br />";
}
}
Here is the part of the other file I need to print the information from the function to:
<?php
if (isset($_SESSION["username"])) {
$eventDAO = new EventDAO($connection);
$event = $eventDAO->findByUsername($_SESSION["username"]);
foreach((array)$event as $e) {
echo $e->getUsername() . ' ' . $e->getDate() . '<br>';
}
}
?>
I'm trying to output the username/date.
Not 100% on this concept.
If you're simply trying to output username/date from one file to another, try using sessions.
public function findByUsername($username) {
$sql = 'SELECT * FROM events WHERE username=? ';
$statement = DatabaseHelper::runQuery($this->connection, $sql, Array($username));
while ($row = $statement->fetch()) {
echo $row['username'] . "<br />";
echo $row['date'] . "<br />";
$_SESSION['getuname'] = $row['username'];
$_SESSION['getdate'] = $row['date'];
}
}
You can then output the information on another php file simply by echoing it out.
echo "Username is ". $_SESSION['getuname'];

How to use PHP to send data over to another page? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a website which is supposed to show some information about food courts from MySQL server and what I have done is that I made it such that the data would be shown in the website and if they click they would be redirected to another web page. My question is how would I be able to check what is the hyperlink they clicked so that I could display accurate information on the second webpage?
What I have done is that I tried to use get to send the information over but to no avail. Can someone guide me please? I am new to PHP and MySQL coding.
This is the PHP code for the website that I am using to display the food court information.
<?php
require 'dbFunction.php';
$con = getDbConnect();
if (!mysqli_connect_errno($con)) {
$result = mysqli_query($con,"SELECT * FROM foodcourt");
while($row = mysqli_fetch_array($result)) {
echo "Foodcourt " . $row['FCNo'] . "<br />";
echo $row['FCDescription'] . "<br />";
echo $row['FCImage'] . "<br />";
echo "<br>";
$data=$row['FCNo'];
}
} else {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_close($con);
?>
And this is the code I use to "receive" the information.
<?php
require 'dbFunction.php';
$con = getDbConnect();
$data = $_GET['$row[FCNo]'];
if (!mysqli_connect_errno($con)) {
$result = mysqli_query($con,
"SELECT * "
. "FROM StallDetails SD AND FoodDetails FD"
. "WHERE FD.StallID = SD.StallID "
. "AND FD.FCNo = ".$data);
while($row = mysqli_fetch_array($result)) {
echo "Foodcourt " . $row['FCNo'] . "<br />";
echo $row['Details']."<br />";
echo $row['Description'].",<br> ";
echo "Price: $".$row['Price']."<br> ";
} }
else {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_close($con);
This is my getDbConnect();
<?php
function getDbConnect() {
// get a database connect to studentacad database
$con = mysqli_connect("localhost:3306", "waduser01", "password123", "p1315774");
Return $con;
}
?>
You are doing it wrong. Your are using $row in get variable too and You are also not enclosing the $data in quotes ''.And one more thing you are not selecting the database. Use mysqli_select_db function to select your database.You are also using AND in selecting the table. use the code below
<?php
require 'dbFunction.php';
$con = getDbConnect();
mysqli_select_db($con,"db_name");
$data = $_GET['fc'];
if (!mysqli_connect_errno($con)) {
$result = mysqli_query($con,
"SELECT * "
. "FROM StallDetails SD , FoodDetails FD"
. "WHERE FD.StallID = SD.StallID "
. "AND FD.FCNo = '".$data."'");
while($row = mysqli_fetch_array($con,$result)) {
echo "Foodcourt " . $row['FCNo'] . "<br />";
echo $row['Details']."<br />";
echo $row['Description'].",<br> ";
echo "Price: $".$row['Price']."<br> ";
} }
else {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_close($con);
Hope this helps you
You don't need to send any data.
Usually, GET variables are used. Example:
Wayne
Would lead to a file called user.php, in which the GET variable id is checked:
$id = isset($_GET['id']) ? $_GET['id'] : false;
In this example, once you have the id, you can decide on what user details to display:
$userDetails = $user->get($id);
Another example:
Wayne
... translates into:
show=recipe
id=34
You are referencing your variable like this:
$_GET['$row[FCNo]'];
But it looks like the variable in the url is fc, so you would access it like this:
$_GET['fc'];

How to loop the $row = mysql_fetch_array($rs);

I have a table
Now.i have a function in my JS
function add()
{
<?php
include('conn.php');
$rs = mysql_query("select * from position");
$row = mysql_fetch_array($rs);
$ss=$row['Name'];
$sss=$row['nowb'];
$ssss=$row['totalb'];
$sssss=$row['nowc'];
$ssssss=$row['totalc'];
echo "add2()";
?>}
function add2(){
AddAddress("<?php echo $ss;?>","<?php echo $sss;?>/<?php echo $ssss;?><br /><?php echo $sssss;?>/<?php echo $ssssss;?>");
}
How to get the every date from my table?
Something like this?
function add() {
<?php
include('conn.php');
$rs = mysql_query("select * from position");
while ( $row = mysql_fetch_array($rs) ) {
$ss=$row['Name'];
$sss=$row['nowb'];
$ssss=$row['totalb'];
$sssss=$row['nowc'];
$ssssss=$row['totalc'];
echo 'AddAddress("' . $ss . '","' . $sss . '/' . $ssss . '<br />' . $sssss . '/' . $ssssss . '");';
}
?>
}
Didn't text the echo 'AddAddress....' line so I hop eI got all the single and double quotes in the right place??
Performing POST requests using Ajax here is an example of sending data from js to php.
also stop naming your vars s,ss,sss,ssss you will have no idea what they mean when you read your code tomorrow..
and try not to use mysql_* functions they have been deprecated switch to mysqli or pdo
I got what would you like to do. In your PHP file:
function add(){
<?php
include('conn.php');
$rs = mysql_query("select * from position");
echo "var data = [] ; "
while($row = mysql_fetch_assoc($rs)){
echo "
data.push({
name: '{$row['Name']}',
nowb: '{$row['nowb']}',
totalb: '{$row['totalb']}',
nowc: '{$row['nowc']}',
totalc: '{$row['totalc']}'
}); \n\r " ;
}
?>
add2(data);
}
function add2(data){
for (var i in data){
var row = data[i] ;
AddAddress(row.name, row.nowb, row.totalb, row.nowc, row.totalc);
}
}
If I understand the question correctly you want to know how to loop through an array in php.
$row = mysql_fetch_array($rs);
foreach($row as $value){
//Do something
}
Read up on it in the docs
http://php.net/manual/en/control-structures.foreach.php

how do i display this columns side by side

im having some problem here. basically, i want to compare columns. so i fetched object and the comparing results appeared just as expected. however, it does not return the compare value anymore after i added the fetch_array to view the current table hoping that the compare value would appear beside the compare value. is there any way i could run the compare code and make it appear the table? i tried a query but it would only work in MySQL and not PHP.
$query = "SELECT * FROM system_audit"; $result = mysql_query($query) or die(mysql_error());
echo " ID Type Setting Value ";
while($row = mysql_fetch_array($result)) {
echo $row['ID'];
echo $row['Type'];
echo $row['Setting'];
echo $row['Value'];
}
while ($row = mysql_fetch_object($result)) {
if($row->Setting != $row->Value) {
echo "X";
} else {
echo "O";
}
}
Your code contains a lot of echo's that have no use. I would suggest learning PHP a bit more.
Your compare is wrong, this should work :
$query = "SELECT * FROM system_audit";
$result = mysql_query($query) or die(mysql_error());
echo " ID Type Setting Value ";
while($row = mysql_fetch_array($result)) {
echo $row['ID'] . "<br>";
echo $row['Type'] . "<br>";
echo $row['Setting'] . "<br>";
echo $row['Value'] . "<br>";
if($row['Setting'] != $row['Value']) {
echo "X" . "<br>";
}
else {
echo "O" . "<br>";
}
echo "<br>";

php mysqli select resultset is not showing anything

Ive been trying to crack this for 2 hours, but something is wrong. I am very much used to doing things without mysqli but read that there is a recommended shift towards it from regular mysql commands. Hence am stuck with following:
<?php
$mysqli = new mysqli('localhost', 'admin', 'test123', 'kadmindb');
if ($result = $mysqli->query("SELECT * FROM records WHERE '$queryType' = '$keyword'")) {
while ($row = $result->fetch_object()) {
echo "<h2>Result:</h2><br>";
echo "ID: " . $row->id . "<br>";
echo "Name: " . $row->cust_name . "<br>";
echo "Invoice No: " . $row->invoice_num . "<br>";
echo "Date: " . $row->date_recorded . "<br>";
}
}
?>
This code is shown in the page where the result of the query should be displayed but nothing is displayed. I checked that both keyword and queryType variables are set and they contain the correct values. Any help would be greatly appreciated. All am trying to do is: select statement to retrieve all the details based on invoice_num submitted.
EDIT: from help I received, I was able to get this working:
$query = "SELECT * FROM records WHERE ".$queryType. " LIKE '%$keyword%' ";
if ($result = $mysqli->query($query)) {
while ($row = $result->fetch_object()) {
echo "<h2>Result:</h2><br><hr/> ";
echo "ID: " . $row->id . "<br>";
echo "Name: " . $row->cust_name . "<br>";
echo "Invoice No: " . $row->invoice_num . "<br>";
echo "Date: " . $row->date_recorded . "<br>";
echo "<hr/>";
}
}
Are you sure there's data to select? This code will only output data if there actually is.
Make sure that $queryType and $keyword are set and have sane values that will yield a result.
Use var_dump($queryType) and var_dump($keyword) immediately before the query. Now check your output. Are they both strings? Run this query directly in PHPMyAdmin and check how many rows you get.
If you can't do that try echo'ing the number of rows returned along with the query values:
if ($result = $mysqli->query("SELECT * FROM records WHERE $queryType = '$keyword'"))
{
while ($row = $result->fetch_object())
{
echo "<h1>Query WHERE '$queryType' = '$keyword' yielded {$result->num_rows} rows!</h1>";
echo "<h2>Result:</h2><br>";
...
Note, you should not have single quotes around the column ($queryType), if you insist you should use backtick quotes (`) but it's unnecessary really - if you're that pedantic you should be using prepared statements.
Also be sure to filter them for any potentially dangerous values that could allow for sql injections. See: mysqli::real_escape_string
Assuming that $queryType is the name of a column in your records table, then I believe the problem is your WHERE clause.
Rather than:
$mysqli->query("SELECT * FROM records WHERE '$queryType' = '$keyword'")
You should have:
$mysqli->query("SELECT * FROM records WHERE {$queryType} = '{$keyword}'")
Note that I've removed the single quotes around $queryType and have used complex (curly) syntax
Also, in the future you might want to try using an else block to trap errors:
$mysqli = new mysqli('localhost', 'admin', 'test123', 'kadmindb');
if ($result = $mysqli->query("SELECT * FROM records WHERE {$queryType} = '{$keyword}'")) {
while ($row = $result->fetch_object()) {
echo "<h2>Result:</h2><br>";
echo "ID: " . $row->id . "<br>";
echo "Name: " . $row->cust_name . "<br>";
echo "Invoice No: " . $row->invoice_num . "<br>";
echo "Date: " . $row->date_recorded . "<br>";
}
}
else
{
echo "Error: " . $mysqli->error;
}

Categories