This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 3 years ago.
I have created on table with a PHP while loop right from the phpmyadmin database fine on page 1 (cpu.php). However, I am not able to send just the name variable ( $row['name'] ) from one selected row to another page, page 2 (cpumore.php). I have tried using sessions and the closest I have come is the code given that outputs the name of my last listed cpu from the cpu.php page to the cpumore.php page. I hope someone can help me pass variables from a selected row to the other table on page 2 (cpumore.php). Thank you so much!
PAGE 1 CPU.PHP
<table id="myTable">
<thead>
<tr>
<th onclick="sortTable(0)">Name</th>
<th onclick="sortTable(1)">Socket</th>
<th onclick="sortTable(2)">Speed</th>
<th>Price</th>
<th></th>
</tr>
</thead>
<?php
session_start();
if(isset($_POST['search'])) {
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT name, socket, speed, price FROM `cpu` WHERE
CONCAT(`name`, `socket`, `speed`, `price`) LIKE
'%".$valueToSearch."%'";
$search_result = filterTable($query);
} else {
$query = "SELECT name, socket, speed, price FROM `cpu`";
$search_result = filterTable($query);
}
// function to connect and execute the query
function filterTable($query)
{
$connect = mysqli_connect("localhost", "root", "", "brodbuilds");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}
?>
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr>
<form action="cpumore.php" method="post">
<td><?php echo $row['name']; $_SESSION['cpuName']=$row['name'];?</td>
<td><?php echo $row['socket'];?></td>
<td><?php echo $row['speed'];?></td>
<td><?php echo $row['price'];?></td>
<td><input type="submit" name=submit id="cpuname" value="Add"/>
</div</td>
</form>
</tr>
<?php endwhile;?>
</table>
PAGE 2 CPUMORE.PHP
<table id="myTable">
<thead>
<tr>
<th onclick="sortTable(0)">Name</th>
<th></th>
</tr>
</thead>
<tr>
<td> <?php session_start(); echo $_SESSION['cpuName'];?> </td>
</tr>
</table>
I would like to be able to click on a button that send the name field from one row to another page.
You missed '>' Try now
<td><?php echo $row['name']; $_SESSION['cpuName']=$row['name'];?></td>
I'm not too sure if I get the question, the best is to have a session manager, or alternatively on more add a variable as page?varname=value on page to use:
$Var = $_Get['varname'];
Related
After succeeding to input new table inside a key in php firebase, now i want to display the result.
I've tried using this
<table>
<tr>
<th>Course Code</th>
<th>Discriptive Title</th>
<th>Unit</th>
<th>Pre-Requisite</th>
<th>Grade</th>
</tr>
<?php
include('dbcon.php');
if(isset($_GET['id']))
{
$key_child = $_GET['id'];
$ref_table = 'User/'.$key_child.'/Grades/1st Year/1st Sem';
$row = $database->getReference($ref_table)->getChild($key_child)->getChild($key_child)->getValue();
if($row > 0 )
{
?>
<tr>
<input type="hidden" name = "id" value = "<?=$key_child;?>">
<td><?=$row['Course_Code']; ?></td>
<td><?=$row['Desc_title']; ?></td>
<td><?=$row['Unit']; ?></td>
<td><?=$row['Pre-Req']; ?></td>
<td><?=$row['Grade']; ?> </td>
</tr>
<?php
}
}
else
{
?>
<td colspan = "5"> No Record found </td>
<?php
}
?>
</table>
but the result was blank instead of returning "No Record found" as stated in the else code
I am trying to display the result from this grandchild table:
here are the href codes that will lead to the blank table if knowing it would help solve the problem
View
this link below will be the one that leads to the above table that doesnt work
samplegrades
Hello I am working a project today. I want to print in front end the data of a specific user every time they login. When they login will get their user id and will fetch data from that specific user only.
I have this database. I want vendor_id 3 when this vendor login will display only values of specific vendor if no values will return "No Commission Data for this user"
Right now heres my wordpress wpdb code
<table border="1">
<tr>
<th>Vendor ID</th>
<th>Total Due</th>
<th>Time</th>
</tr>
<?php
global $wpdb;
$result = $wpdb->get_results ( "SELECT * FROM wp_pv_commission" );
$vendor = get_current_user_id();
foreach ( $result as $userdata) {
?>
<tr>
<td><?php echo $userdata->vendor_id;?></td>
<td><?php echo $userdata->total_due;?></td>
<td><?php echo $userdata->time;?></td>
</tr>
<?php
}
?>
</table>
And it returns the data of this. But what I want is only as per user like right now Im login as vendor id 3. It show all. What is the proper wordpress php conditioning code I need to use
Thank you for your answer.
Your code is right but your condition is wrong for selecting the data from database
when you don't apply where clause, MYSQL will always return all the records. so for that you need to provide where clause in your query
<table border="1">
<tr>
<th>Vendor ID</th>
<th>Total Due</th>
<th>Time</th>
</tr>
<?php
global $wpdb;
$vendor = get_current_user_id();
$result = $wpdb->get_results ( "SELECT * FROM wp_pv_commission where vendor_id=".$vendor );
foreach ( $result as $userdata) {
?>
<tr>
<td><?php echo $userdata->vendor_id;?></td>
<td><?php echo $userdata->total_due;?></td>
<td><?php echo $userdata->time;?></td>
</tr>
<?php
}
?>
</table>
How to use where clause in MySQL
This question already has answers here:
How to view query error in PDO PHP
(5 answers)
How can I get useful error messages in PHP?
(41 answers)
Closed 2 years ago.
sorry to bother you guys, but been trying everything i could to get some data from database, and all the time it show's me blank, so i'm getting blank flashes as well :)
So what i need to to is,
as you see on the pic, i have a column ownerId with repeated data, this is ok, i work's like that, now what i want extract from the database is to show the itemId and count where ownerId = ?.
So have my query as bellow.
<table id="zctb" class="display table table-striped table-bordered table-hover" cellspacing="0" width="100%">
<thead>
<tr>
<th>#</th>
<th>Item Name</th>
<th>Item ID</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT ownerId, itemId, count from user_item where ownerId = :editid";
$query = $dbh2 -> prepare($sql);
$query->bindParam(':editid',$editid,PDO::PARAM_INT);
$query->execute();
$result=$query->fetch(PDO::FETCH_ASSOC);
$cnt=1;
if($query->rowCount() > 0){
foreach($results as $result){
?>
<tr>
<td><?php echo htmlentities($cnt);?></td>
<td><?php echo htmlentities($result->item_name);?></td>
<td><?php echo htmlentities($result->itemId);?></td>
<td><?php echo htmlentities($result->count);?></td>
</tr>
<?php
$cnt=$cnt+1;
}
}
?>
</tbody>
</table>
but this don't return anything not even not data found on the table.
any idea?
1) Check if you have a value in the variable $editid
2) you have an error in iterating over an array:
foreach ($results as $result) // you don't have a $results variable
I have a mysql table with orders. I am trying to loop through the orders table and select individual client orders according to their user id and display the orders on their client accounts. However, my code below just prints the first row and repeats it endlessly jaming my browser every time.
what is wrong with this and how to i solve it
<?php
$records = $conn->prepare('SELECT * FROM orders WHERE user_id= :id');
$records-> bindParam(':id', $_SESSION['user_id']);
$records->execute();
$results=$records->fetch(PDO::FETCH_ASSOC);
$i=0;
while($i<=$results):
$i++;
?>
<h3>Your Orders</h3>
<table >
<tr >
<th>Order Number</th><th>Academic Level</th><th>Order Details</th>Manage Order</th>
</tr>
<tr>
<td>#SJ<?=$results['id']; ?> </td><td><?=$results['academic_level']; ?></td><td ><?=$results['details']; ?></td>
</tr>
</table>
<?php
endwhile;
?>
Remove all $i related code. Just move your fetch statement to while condition, like the following:
while( $results=$records->fetch(PDO::FETCH_ASSOC))
You need to include the html code in the while loop because you want to display all of the orders.
I'm using this method, try this out.
Start while in first php section
<?php
$username = $_SESSION['username'];
$sql = $db->prepare("SELECT * FROM tableName WHERE username = '$username' ");
$sql->execute();
while($results=$sql->fetch(PDO::FETCH_ASSOC)){
?>
After that the html section coming:
<h3>Your Orders</h3>
<table >
<tr >
<th>Order Number</th><th>Academic Level</th><th>Order Details</th>Manage Order</th>
</tr>
<tr>
<td><?php echo $results['id']; ?> </td><td><?php echo $results['academic_level']; ?></td><td ><?php echo $results['details']; ?></td>
</tr>
</table>
and here the ending
<?php
}
?>
I currently have a long list that is being generated by PHP from a MySQL. It has 3 columns and the HTML for it looks roughly like:
<thead>
<tr>
<th style="display:none;">IP</th>
<th>ID</th><th>Status</th>
<th>Selection</th>
</tr>
</thead>
<tbody>
<?php while($a = $ks->fetch(PDO::FETCH_ASSOC)) { ?>
<tr>
<td style="display:none;"><?php echo $a['ip'];?></td>
<td><?php echo $a['id'];?></td>
<td><?php echo getstatus($a['status']);?></td>
<td><input type="checkbox" data-status="<?php echo getstatus($a['status']);?>" onclick="redes(this)" value="<?php echo $a['ip'];?>"></td>
</tr>
<?php }?>
Now, in every table column next to the TH text there are 2 arrows (one up and down) and you can sort them accordingly. I want to know how I can have one row sorted ASC by default when visiting the page?
eg.
<?php
$sort = $_GET['sort'] ?: 'ip';
$sql = 'SELECT ip,status,section FROM tab ORDER BY '. $sort;
$ks = $db->query($sql);