doctorbill
asked on
Help with php echo
<?php
$query = $conn->prepare("SELECT sup_id, sup_ticketnumber, sup_company, sup_contact, sup_email, sup_phone, sup_rep, sup_comments, sup_addcom1, sup_addcom2, sup_addcom3, sup_editcom1, sup_editcom2, sup_editcom3, sup_todo, sup_timefrom, sup_timeto, sup_date, radnew, radinprogress, radclosed, radnocategory, chkemail, chkphone, chksms, chkproject FROM support ORDER BY sup_date asc");
$query->execute();
$results = $query->get_result();
?>
I need to echo out the sum of the sup_id column
Help please
ASKER
<?php
// Let's run the query
$query = $conn->prepare("SELECT sup_id, sup_ticketnumber, sup_company, sup_contact, sup_email, sup_phone, sup_rep, sup_comments, sup_addcom1, sup_addcom2, sup_addcom3, sup_editcom1, sup_editcom2, sup_editcom3, sup_todo, sup_timefrom, sup_timeto, sup_date, radnew, radinprogress, radclosed, radnocategory, chkemail, chkphone, chksms, chkproject FROM support ORDER BY sup_date asc");
$query->execute();
$results = $query->get_result();
<?php while ($row = $results->fetch_assoc()):$style = "";
?>
<table id="customers">
<tr>
<th>ID:</th>
<th>Ticket Number:</th>
<th>Company:</th>
<th>Contact:</th>
<th>Ticket Status:</th>
<th>Ticket Status:</th>
<th>Ticket Status:</th>
<th>Ticket Status:</th>
</tr>
<tr>
<td><?= $row['sup_id'] ?> <?php echo "<a href=\"FileEdits/viewformSupportTickets.php?id=" . $row['sup_id'] ."\" target=\"_blank\">RecordLink... </a>"; ?></td>
<td><?= $row['sup_ticketnumber'] ?></td>
<td><?= $row['sup_company'] ?></td>
<td><?= $row['sup_contact'] ?></td>
<td <?php echo $style2 ?>></td>
<td <?php echo $style3 ?>></td>
<td <?php echo $style4 ?>></td>
<td <?php echo $style5 ?>><?= $row['radnew'] ?></td>
</tr>
</table>
<?php endwhile; ?>
?>
Question:Where do I put your script so that the echo is at the end of the table and does not disrupt the current structure?
Try:
<?php
// Let's run the query
$query = $conn->prepare("SELECT sup_id, sup_ticketnumber, sup_company, sup_contact, sup_email, sup_phone, sup_rep, sup_comments, sup_addcom1, sup_addcom2, sup_addcom3, sup_editcom1, sup_editcom2, sup_editcom3, sup_todo, sup_timefrom, sup_timeto, sup_date, radnew, radinprogress, radclosed, radnocategory, chkemail, chkphone, chksms, chkproject FROM support ORDER BY sup_date asc");
$query->execute();
$results = $query->get_result();
$sum = 0;
while ($row = $results->fetch_assoc()):
$style = "";
$sum += $row['sup_id'];
?>
<table id="customers">
<tr>
<th>ID:</th>
<th>Ticket Number:</th>
<th>Company:</th>
<th>Contact:</th>
<th>Ticket Status:</th>
<th>Ticket Status:</th>
<th>Ticket Status:</th>
<th>Ticket Status:</th>
</tr>
<tr>
<td><?= $row['sup_id'] ?> <?php echo "<a href=\"FileEdits/viewformSupportTickets.php?id=" . $row['sup_id'] ."\" target=\"_blank\">RecordLink... </a>"; ?></td>
<td><?= $row['sup_ticketnumber'] ?></td>
<td><?= $row['sup_company'] ?></td>
<td><?= $row['sup_contact'] ?></td>
<td <?php echo $style2 ?>></td>
<td <?php echo $style3 ?>></td>
<td <?php echo $style4 ?>></td>
<td <?php echo $style5 ?>><?= $row['radnew'] ?></td>
</tr>
</table>
<?php endwhile;
echo '<p>Total: ', $sum,'</p>';
?>
ASKER
If I use this I get page not displayed error
ASKER
Sorry - working now. Just one change - how do I sum the number of records rather than sum the values
ie If there are 20 records in the recordset how do I show this as an echo value
ie If there are 20 records in the recordset how do I show this as an echo value
You should be able to use the num_rows propery of the result:
echo $results->num_rows;
echo $results->num_rows;
ASKER
I get this:
Notice: Undefined variable: result in C:\xampp\htdocs\Developmen t\Inventas \Sites\Tic ketStatus_ AllStatusS earchMetri cs.php on line 83
Notice: Trying to get property of non-object in C:\xampp\htdocs\Developmen t\Inventas \Sites\Tic ketStatus_ AllStatusS earchMetri cs.php on line 83
Notice: Undefined variable: result in C:\xampp\htdocs\Developmen
Notice: Trying to get property of non-object in C:\xampp\htdocs\Developmen
ASKER
This is the code giving the error:
$query->execute();
$results = $query->get_result();
[b] $row_cnt = $result->num_rows;[/b]
$sum = 0;
$sum2 = 0;
while ($row = $results->fetch_assoc()):
$style = "";
$sum += $row['sup_id'];
$sum2 += $row['radinprogress'];
?>
<?php endwhile;
echo '<p>Total: ', $sum,'</p>';
echo '<p>Total2: ', $sum2,'</p>';
[b]printf("Result set has %d rows.\n", $row_cnt);[/b]
?>
ASKER
Sorry - The and tags are not in the code
ASKER
I mean the
[b] and [/b] tags
ASKER
This is the undefined variable:
$row_cnt = $result->num_rows;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I cannot believe I missed that. Thanks - perfect
ASKER
Closed
ASKER
Thanks so much for your help
You're welcome!
Open in new window