Hi all ,
I am trying to display order details when I clicked on in an order row view. On clicking view with respect to order id in order info respective order details will be displayed in a 'tr'in same page using ajax.
Can any body post any link or any code .Because it is very urgent.

Thanks,
Subrata

Dani AI

Generated

As noted, helpers need your platform/schema and sample markup — but here is a minimal, practical pattern you can paste and adapt so clicking a row inserts a details <tr> beneath it. : include your actual table/SQL when asking for specific fixes.

Example table row (add data-order-id to each order):

<table id="orders">
  <thead><tr><th>Order</th><th>Date</th><th>Total</th><th></th></tr></thead>
  <tbody>
    <tr data-order-id="123">
      <td>#123</td><td>2025-11-29</td><td>$42.00</td><td><button class="view">View</button></td>
    </tr>
  </tbody>
</table>

Client-side: event delegation, fetch details, insert a details row after the clicked row.

document.getElementById('orders').addEventListener('click', function(e) {
  if(!e.target.classList.contains('view')) return;
  const row = e.target.closest('tr');
  const id = row.dataset.orderId;
  const open = document.querySelector('.order-details');
  if(open) open.remove(); // toggle single open details
  fetch('order_details.php', {
    method: 'POST',
    headers: {'Content-Type':'application/json'},
    body: JSON.stringify({order_id: id})
  })
  .then(r => { if(!r.ok) throw new Error('Network error'); return r.json(); })
  .then(data => {
    if(!data.success) throw new Error(data.error || 'No data');
    row.insertAdjacentHTML('afterend', data.html);
  })
  .catch(err => console.error(err));
}, false);

Server-side (PHP + PDO): validate input, check auth, prepare statements, return JSON with an HTML fragment.

<?php
header('Content-Type: application/json; charset=utf-8');
$data = json_decode(file_get_contents('php://input'), true);
$order_id = isset($data['order_id']) ? (int)$data['order_id'] : 0;
if($order_id <= 0){ echo json_encode(['success'=>false,'error'=>'Invalid id']); exit; }
// TODO: verify logged-in user owns $order_id
$pdo = new PDO('mysql:host=localhost;dbname=shop;charset=utf8mb4','user','pass',[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);
$stmt = $pdo->prepare('SELECT p.name, oi.qty, oi.price FROM order_items oi JOIN products p ON p.id = oi.product_id WHERE oi.order_id = ?');
$stmt->execute([$order_id]);
$items = $stmt->fetchAll(PDO::FETCH_ASSOC);
if(!$items){ echo json_encode(['success'=>false,'error'=>'No items']); exit; }
$html = '<tr class="order-details"><td colspan="4"><table><tr><th>Product</th><th>Qty</th><th>Price</th></tr>';
foreach($items as $it){ $html .= '<tr><td>'.htmlspecialchars($it['name']).'</td><td>'.(int)$it['qty'].'</td><td>'.number_format($it['price'],2).'</td></tr>'; }
$html .= '</table></td></tr>';
echo json_encode(['success'=>true,'html'=>$html]);

Troubleshooting/security: check browser console and Network tab, ensure same-origin or set CORS, return proper JSON headers, escape all output to prevent XSS, validate orders against the logged-in user, and use prepared statements. If posting back here, include your table HTML, JS, PHP and a sample DB schema so replies can be exact.

Recommended Answers

All 2 Replies

This would be really hard to do without knowing your platform, database schema, or any of your code.

Member Avatar for Member #120589

:

Please read this...

https://www.daniweb.com/web-development/php/threads/435023/read-this-before-posting-a-question

We assume that all new members posting to this forum have read the first thread titled "Read This Before Posting A Question", but I guessed you missed it.

Here are some of the more relevant points:

  • Ask a question that can be answered. Do not ask "What's wrong with my code?", "Why doesn't this work?" or anything else that does not give us useful information
  • We're not psychic. Please organize your thoughts and provide as much information as possible to get us onto the same page. If we have to play 20 questions just to get enough information to help you, your question is more likely to go unanswered.
  • Post your code. If we don't know what you did, how can we possibly help?
  • Do not post your requirements and nothing else. We view that as a lazy do-nothing student that wants us to do their work for them. That's cheating and we will be hard on you.
  • Do not tell us how urgent your problem is. Seriously, for us there is no urgency at all. Many that can help will ignore any URGENT or ASAP requests.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.