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>";
Related
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>';
I am having a little bit of trouble trying to format a table to the way I want it. It is supposed to display a list of all movie ids in one column and then a dropdown in the next allowing the user to change the pay status.
The desired result is as such :
-- Movie Id -----------Pay Status-------
[___id 1____] [____dropdown_____]
[___id 2____]
[___id 3____]
However I am currently getting something like this :
-- Movie Id -----------Pay Status-------
[___id 1____]
[___id 2____]
[___id 3____]
[____dropdown_____]
The code i am working on is below :
echo "<tr>
<th>Title</th>
<th>Pay Status</th>
</tr>";
while ($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row ["movieid"] . "</tr>";
}
//// pay status
echo "<td>" . "<select name='payid'>";
while ($row = $result5->fetch_assoc()) {
echo "<option value='" . $row['payid'] . "'>" . $row['payid'] . "</option>";
}
echo "</select>" . "</td>";
Any help is appreciated. Thank you.
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']
I'm showing data from Mysql table with php inside HTML table, but i need 2 more things to accomplish to the table:
1- How to Alternate colors for table rows to use 4 different css classes, I am using now class='success' i have 3 more that i want to use and each one should apply to each table row, how to do it? any simple example like a loop or something?
2- Data showing from the oldest record in the table to the latest one, and i want to show the reverse, so the last record shows first in the html table.
My code for this table:
<?php echo "<table class='table'>
<thead>
<tr>
<th>Order#</th>
<th>Name</th>
<th>Total</th>
<th>Submitted On</th>
<th>Status</th>
</tr> </thead>";
while($row = mysqli_fetch_array($result))
{
echo "<tr class='success'>";
echo "<td>" . $row['lite_order_id'] . "</td>";
echo "<td>" . $row['lite_item_name'] . "</td>";
echo "<td>" . $row['lite_email'] . "</td>";
echo "<td>" . $row['lite_country'] . "</td>";
echo "<td>" . $row['lite_order_total'] . "</td>";
echo "</tr>"; }
echo "</table>"; ?>
1 - Use id attribute to style individual elements. Check it out here
2 - In your MySQL query, use ORDER BY:
(I presume you have an id column here)
$query = "SELECT * FROM `yourtable` ORDER BY `id` ASC";
See here
To get reverse records you can use mysql ORDER BY clause or PHP function array_reverse()
I have a problem here I can't solve. I have a database of houses with country, location, price etc entities. I print only the countries in a table using:
while ($data = mysql_fetch_array($select))
where $select is a query that selects specific data from the db. I want to display the full information of the selected db data on a different page i have created. The problem is that i don't know how to take the price of the data the user selected. When i get the price of the $_SESSION['counter'], its the number of the last entity of the db. . I don't want to use javascript etc. Here's the code of the page:
<?php
require_once 'php/core.php'; // opens the database
require_once 'php/openDB.php'; // starts the new session
$select = mysql_query("SELECT ID, Country, City FROM Houses");
$counter = 1;
echo "<form action='house_profile.php' method='get'>
<table width='400'>
<tr>
<td>No.</td>
<td>Country</td>
<td>City</td>";
echo "<tr>";
while ($data = mysql_fetch_array($select))
{
echo "<tr>";
echo "<td>" . $counter . "</td>";
echo "<td>" . $data['Country'] . "</td>";
// echo "<td>" . "<a href='house_profile.php' type='submit' value='$counter'>" . $data['City'] . "</a>" . "</td>";
echo "<td>" . $data['City'] . "</td>";
echo "<td><input type='submit' value='info' name='" . $counter . "'></td>";
echo "</tr>";
$_SESSION['counter'] = $counter;
$counter++;
}
echo "</table>
</form>";
?>`
Clarification:
You can pass any value to house_profile.php by adding a ? to start the querystring, then the name of the variable and the value. If you want to pass the id to house_profile then the link should look like this.
"<a href='house_profile.php?ID=" . $data['ID'] . "'>"
then in house_profile.php update your query like this
$select = mysql_query("SELECT * FROM Houses where ID = " . $_GET['ID']);
Now only the entity they clicked will be available.
FYI $counter is just the count, it's not necessarily the ID of the entity. e.g. if you delete ID 1 your records will start from ID 2 but counter will always start with 1. So to reference your entities correctly use the database ID.
Your query retrieves each house's ID from the database but doesn't display this (unless I don't understand your code). When the user chooses a house, you have to retrieve the ID and then use this in a separate query, such as
select price
from houses
where id = :ID
Currently you're displaying a line counter on your form as opposed to the house's ID - which explains why you write...
When i get the price of the $_SESSION['counter'], its the number of the last entity of the db.
You're passing the value of the row counter to the second query instead of the house's ID.