All Params Not Being Passed - php

I am using php to create a hyperlink, and pass 3 params when the hyperlink is clicked. My issue with the syntax below is that only the 1st param is passsed, the other 2 are ignored.
What should I alter in the syntax below so that all 3 params are passed?
if($number_of_rows > 0) {
echo '<table border="1">';
echo '<tr>';
echo ' <th bgcolor="#FFFFFF" >Name </th>';
echo ' <th bgcolor="#FFFFFF">User ID </th>';
echo ' <th bgcolor="#FFFFFF">Dollar Amt </th>';
echo ' <th bgcolor="#FFFFFF">Price 1 </th>';
echo ' <th bgcolor="#FFFFFF">Price 2 </th>';
echo ' <th bgcolor="#FFFFFF">Price 3 </th>';
echo ' <th bgcolor="#FFFFFF">Price 4 </th>';
echo ' <th bgcolor="#FFFFFF">Items Sold </th>';
echo ' <th bgcolor="#FFFFFF">Items On Sale</th>';
echo '</tr>';
while ($Row = mssql_fetch_assoc($result))
{
echo '<tr><td>' . $Row['Name'] . '</td><td>' . $Row['User ID'] .
'</td><td>' . "$".round($Row['Dollar Amt']) . '</td><td>' . "$".round($Row['Price 1']) .
'</td><td>'. "$".round($Row['Price 2']) . '</td><td>'. "$".round($Row['Price 3']) .
'</td><td>'. "$".round($Row['Price 4']) . '</td><td>' . $Row['Items Sold'] .
'</td><td><a href="Test.php?name='.$Row['Name'].'"&begin=".$begin"&finish=".$finish>'.$Row['Items On Sale'].'</a></td></tr>';
}
The above runs a sql server stored procedure and I am using echo to create a table and return to my page. That process works as it should. The only issue is that only name is passed into the url when clicked not the 2 dates that I also want to pass.
NOT a duplicate, that is pertinate to mysql and I am using mssql. Also, the linked duplicate talks about returning rows, now passing parameters. My issue is that only the name parameter is passed when clicked. Please remove the duplicate flag.
EDIT
The variables are defined like so:
$begin = $_GET['begin'];
$end = $_GET['end'];

You are mixing double-quote " and single-quote '. Replace last line of your code inside while loop with following and it should work as expected.
'</td><td>'.$Row['Items On Sale'].'</td></tr>';
From your post edit, try this:
'</td><td>'.$Row['Items On Sale'].'</td></tr>';

Related

Get Value Of Table Field

I am using php to echo query results out to a table like so
echo '<table border="1">';
echo '<tr>';
echo ' <th bgcolor="#FFFFFF" >Team Name </th>';
echo ' <th bgcolor="#FFFFFF" >Player Name </th>';
echo ' <th bgcolor="#FFFFFF">Jersey Number </th>';
echo '</tr>';
while ($Row = mssql_fetch_assoc($result))
{
echo '<tr><td>' . $Row['Team Name'] . '</td><td>' . $Row['Player Name'] . '</td><td>' . $Row['Jersey Number'] . '</td></tr>';
}
echo '</table>';
};
I want Jersey Number to be a hyperlink which can read the value of Player Name and pass that to a php file to be used as a query parameter and pull data for that specific player when the page loads.
Sample data is like
Team Name --- Player Name --- Jersey Number
Red Bob Jones 12
Blue Jack Horner 14
So if you click on 14, the code would read Jack Horner and store it in a variable. How is this achieved with php/html?
EDIT
Something like this is what I am after...using one page to redirect to and passing in the player name to use as a parameter.
Brief explanation, set the hyperlink to a page called other.php, and pass in the as part of the QueryString the value of .$row['name']
I tried the below syntax, but it gives me a 500 error
echo "<td><a href='other.php?playername=".$row['Player Name']'>" . $row['Player Name'] . "</a></td>";

PHP dynamic HTML table using SQL

Background
I am using the below code to generate a HTML table based on SQL results.
Code
$stid = oci_parse($conn, "
SELECT *
FROM
(
SELECT orders.order_no, orders.porder_no, orders.date, order_totals.value
FROM orders, order_totals
WHERE orders.order_no = order_totals.order_no
AND orders.account_no = '" . $_SESSION['session_account'] . "'
ORDER BY orders.order_no DESC
)
WHERE ROWNUM <= 15
");
oci_execute($stid);
echo "<table class='table'>
<thread>
<tr>
<th>Order No</th>
<th>Purchase Order No</th>
<th>Date</th>
<th>Value</th>
</tr>
</thread>
<tbody>";
while ($row = oci_fetch_array($stid, OCI_NUM)) {
echo "<tr>";
echo '<td>' . $row['0'] . '</td>';
echo "<td>" . $row['1'] . "</td>";
echo "<td>" . $row['2'] . "</td>";
echo "<td>" . $row['3'] . "</td>";
echo "</tr>";
unset($row);
}
echo "</tbody>
</table>";
Question
Is it possible to make the HTML table generation part in the code more dynamic, so that if I need to add an additional column for example I can just ammend the SQL part in the code?
I had an idea to set the column headings using AS in SQL and I can amend the SQL to use AS to show the real column headings I want for example
SELECT orders.order_no AS "Order No"
, orders.porder_no AS "Purchase Order No"
, orders.date AS "Date"
, order_totals.value AS "Total"
but what about the HTML table part, is there some method to just print all columns and rows dynamically, like maybe create a function printTable that would handle any table?
The $row var is an array so you can loop over that too. Since you want to treat your first field differently write it out before the loop and start the loop at 1.
while ($row = oci_fetch_array($stid, OCI_NUM)) {
echo "<tr>";
echo '<td>' . $row[0] . '</td>';
for ( $ii = 1; $ii < count($row); $ii++ ) {
echo "<td>" . $row[$ii] . "</td>";
}
echo "</tr>";
}
I don't know what the unset($row) was for, so I left it out.
You can use:
SELECT * FROM {TABLENAME}
Then fetch an array.
You can get data with $row['{FIELDNAME}']
You can use double loop:
$results = $PDO->fetchAll(PDO::FETCH_ASSOC); // here is all columns and rows from db query.
echo '<table><tr>';
// loop only first row to get header
foreach ($results[0] as $header => $value) {
echo "<th>{$header}</th>"
}
echo '</tr>';
// loop all rows
foreach ($results as $row) {
echo '<tr>';
// and loop any number of columns
foreach ($row as $cellName => $cell) {
// If you have only one special case, than use if statement
switch ($cellName) {
case 'order_no':
echo "<td><a href='http://example.com/getOrder?id={$cell}'>{$cell}</a></td>";
break;
default: echo "<td>{$cell}</td>";
}
}
echo '</tr>';
}
echo '</table>';

php links in a table based on sql query

I am populating a table using php from an array (populated by an mysql query). The table code I am using is:
<thead>
<tr>
<hr>
<th>UserName</th>
<th>Nick Name</th>
<th>Role</th>
<th>Unit</th>
<th>Active</th>
<th>Admin</th>
</tr>
</thead>
<tbody>
<?php
foreach ($portfolio as $row)
{
echo("<tr>");
echo("<td>" . $row["username"] . "</td>");
echo("<td>" . $row["nickname"] . "</td>");
echo("<td>" . $row["role"] . "</td>");
echo("<td>" . $row["unit"] . "</td>");
echo("<td>" . $row["active"] . "</td>");
echo("<td>" . $row["isadmin"] . "</td>");
echo("</tr>");
}
?>
I have been trying without luck to find a way to have the first column in the table a hyperlink that allows editing of that users details (IE redirects to another page/php). The array itself is being populated using this code:
//now lets get the user's stock info
foreach ($rows as $row)
{
$stock = lookup($row["username"]);
$stock["username"] = $row["username"];
$stock["nickname"] = $row["nickname"];
$stock["role"] = $row["role"];
$stock["unit"] = $row["unit"];
$stock["active"] = $row["active"];
$portfolio[] = $stock;
}
How can I make the results of the sql query / php a link within the table?
Thanks for the help, I am new to php/mysql and trying to find my feet;
Andy
You'll need to do something like the following, then on your user edit page you can get the username with $_GET['user']
<?php
foreach ($portfolio as $row)
{
echo("<td><a href='user-edit.php?user=" . $row["username"] . "'>" . $row["username"] . "</a></td>");
}
?>
Given an unique username ofc, else you can do it with the id or any unique field.
Why do you use $portfolio variable ? It just stock the data you already have in $rows.
Then, just use this :
echo '<td>
'. $row["username"] .'
</td>';
I think you have an user ID in your table ?
Simply changing this line
echo("<td>" . $row["username"] . "</td>");
to this
echo("<td>" . $row["username"] . "</td>");
will make the first column clickable. Of course you'll need to fill in the target of the link. Making the details editable is a lot more code though.

How to submit parameters by hyperlink-url and retrieve them in php?

Carrying values in a while cycle, each value is extracted from a SQL table, and I need to carry em in a since I'm making a list of items purchased from a specific client. I'm using this line for the href url:
echo "<table width=1200 style align=left>";
while($row3 = mysqli_fetch_array($rs3)){
$space = array("");
$text=$row3['description'];
$dash="_";
$url = preg_replace("![^a-z0-9]+!i", "_", $text);
$url= "".$url.".php";
echo "<tr><td colspan=2 style align=center><span class=font>" . $row3['relid'] . "</span></td><td width=132 style align=center><span class=font>" . $row3['invoiceid'] . "</span></td><td width=400 style align=center <span class=font><a href=$url>" . $row3['description'] . "</span></A></td><td width=132 style align=right><span class=font>" . $row3['amount'] . "</span></td><td width=132 style align=center><span class=font>Pendiente</span></td><td width=132 style align=left><span class=font>" . $row3['duedate'] . "</span></td></tr>";
}
mysqli_close($con3);
echo "</table>";
echo"<table width=1200>";
echo " <tr class=font>
<td width=1200 height=22 colspan=7 background=border-green-horizontal.png> </td>
";
I'm generating the url from the Description I extract from the database but I need to carry the Order ID, Client ID, etc from the specific row.
Each variable is needs to be carried to a form where the user will fill some fields regarding the product the client bought (Medical Test Results), and I need those variables to mark as "Done" so It won't show up again on the list.
Fix these syntax errors, report back if still broken.
<td width=400 style align=center <span class=font><a href=$url>" . $row3['description'] . "</span></a></td>
-->
"<td width=400 style align='center'><span class='font'><a href='$url'>" . $row3['description'] . "</span></a></td>"
EDIT:
Do you mean how to append a var to an url, so it can be retrived on the called page?
You can append the var to the url by echo "<a href='{$url}?id={$var}'>.
On the called page, you can read it by $_GET['id']

How to Multiply two Column values and display its Result at the end of each Row?

http://www.koolfree.com/ImageUpload/uploads/1340729929.jpg (Table Image)
Hello, I have linked to an Image (because stackoverflow was not allowing me to upload due to less than 10 reputation) in which you can see there is a Table with 9 Columns and 3 Rows and the Table is connected to the Database and all the values in the table are stored in the Database.
As you can see there is a Last Column of Total in which I want to display the Multiplication Result of Days and Salary values individually Row-wise.
E.g.
user456 has worked 30 Days and his Salary is 100, so it should multiply 30 by 100 and generate the result i.e. 3000 and the result should be displayed in Last Column of Total <>amount.
Similarly,
user123 has worked 30 Days and his Salary is 250, so it should multiply 30 by 250 and generate the result i.e. 7500 and the result should be displayed in Last Column of Total <>amount.
I have used the following code in the Table and sharing for your assistance.
<?php
/*
VIEW.PHP
Displays all data from 'accounts' table
*/
// connect to the database
include('connect-db.php');
// get results from database
$result = mysql_query("SELECT * FROM accounts")
or die(mysql_error());
// display data in table
echo "<p><b>View All</b> | <a href='view-paginated.php?page=1'>View Paginated</a></p>";
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>No</th> <th>Name & ID</th> <th>Days</th> <th>OverTime</th> <th>Date</th> <th>Salary</th> <th>Edit</th><th>Delete</th><th>Total</th></tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['keywords'] . '</td>';
echo '<td>' . $row['title'] . '</td>';
echo '<td>' . $row['description'] . '</td>';
echo '<td>' . $row['date'] . '</td>';
echo '<td>' . $row['salary'] . '</td>';
echo '<td>Edit</td>';
echo '<td>Delete</td>';
echo '<td><>amount</a></td>';
echo "</tr>";
}
// close table>
echo "</table>";
?>
Kindly tell me what additions or changes should I made to the codes to generate the requisite result?
http://www.koolfree.com/ImageUpload/uploads/1341093148.jpg
I have attached a link of Screenshot. Kindly see the Screenshot and tell me how can I add multiple jobs per user ID?
Have you tried this:
...
echo '<td>' . $row['salary'] . '</td>';
echo '<td>Edit</td>';
echo '<td>Delete</td>';
echo '<td>' . $row['title']*$row['salary'] . '</td>';
echo "</tr>";
...
To add the total of all rows in one column you need to use a variable which gets incremented each time the while loop goes through:
// Declare variable for the place where the value
// of all the elements of the column are stored
$Total_total=0;
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {
...
echo '<td>' . $row['title']*$row['salary'] . '</td>';
echo "</tr>";
//Increment the value of the Total_total variable
//by the salary value of one row till the while loop finishes
$Total_total=$Total_total+$row['title']*$row['salary'];
}
// After the while loop add one more row where the "total's" will be shown
echo "<tr>";
echo '<td>' . Id column totals . '</td>';
echo '<td>' . Totals . '</td>';
echo '<td>' . Totals . '</td>';
echo '<td>' . Totals . '</td>';
echo '<td>' . Totals . '</td>';
echo '<td>' . Totals . '</td>';
echo '<td>' . Totals . '</td>';
echo '<td>' . Totals . '</td>';
echo '<td>' . $Total_total . '</td>';
echo "</tr>";
// Do the same for all the other columns where a total count is needed.
// 1) Declare variable ("$Total_total=0;")
// 2) Increment it each time with itself and something you
// need the totals for when while loop goes through one time
// ("$Total_total=$Total_total+$row['salary'];")
// 3) Print out the results after the while loop
// ("echo '<td>' . $Total_total . '</td>';")

Categories