Retrieving records from mysql [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Just looking for better solution.I'm retrieving all the records from mysql. Then I will send this data by email. Its working fine. Is there any better solution? thanks
$query = "SELECT * FROM order_details WHERE order_id = '".$data['order_id']."'";
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$message_admin .= "<table style='text-align:center;' border='1' cellspacing='0' cellpadding='7'>
<tr>
<td>Source</td>
<td>".$data['source']."</td>
</tr>
<tr>
<td>Email</td>
<td>".$data['email']."</td>
</tr>
<tr>
<td>Message</td>
<td>".$data['message']."</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>";
}

You would benefit from: http://us.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
Instead of the complicated string manipulation you are doing now.
You are setting $row, but using $data?

I would take a look at the following to improve your code.
mysql-real-escape-string
SELECT * vs SELECT column

Related

Display selected values in mysqli columns [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
All i want to do is to output only Agric Department inside the Department columns. How do i go about this. Thanks in advance. This is my code.
<thead>
<tr>
<th>SL</th>
<th>Student Name</th>
<th>Department</th>
<th>Age</th>
<th>Photo</th>
</tr>
</thead>
<tbody>
<?php
$query=mysqli_query($db_con,'SELECT *
FROM `student_info`
ORDER BY `student_info`.`datetime` DESC;');
$i=1;
while ($result = mysqli_fetch_array($query)) { ?>
<tr>
<?php
echo '<td>'.$i.'</td>
<td>'.ucwords($result['name']).'</td>
<td>'.ucwords($result['department']).'</td>
<td>'.ucwords($result['age']).'</td>
<td><img class="rounded-circle avatar-xl" src="../../images/'.$result['photo'].'" ></td>';?>
</tr>
<?php $i++;} ?>
</tbody>
</table>
What am trying to achieve is to display only students in Agric Department
change your query from
SELECT * FROM `student_info` ORDER BY `student_info`.`datetime` DESC
to
SELECT * FROM `student_info` where department = 'Agric' ORDER BY `student_info`.`datetime` DESC

Make email address in table clickable, opening send email [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
My table gets populated from my phpmyadmin database in php:
while($row2 = mysqli_fetch_array($result2))
{
$dataRow2 = $dataRow2."
<tr>
<th>Event Name</th>
<th>$row2[1]</th>
<th>Location</th>
<th>$row2[2]</th>
<th>Description</th>
<th>$row2[3]</th>
<th>Date</th>
<th>$row2[4]</th>
<th>Cost</th>
<th>$row2[5]</th>
<th>Email</th>
<th>$row2[6]</th>
</tr>";
}
And is in the HTML as so:
<table>
<?php echo $dataRow2;?>
</table>
I want to make the last th (the email address) clickable, opening a sendto for the user to email the address. How is this achievable?
Assuming the email is $row2[6], you would want to replace it with
<th>$row2[6]</th>
This will change it to a link with the email address still visible in the table.
You can use anchor tag mailto to clickable like the following
while($row2 = mysqli_fetch_array($result2))
{
$dataRow2 = $dataRow2."
<tr>
<th>Event Name</th>
<th>$row2[1]</th>
<th>Location</th>
<th>$row2[2]</th>
<th>Description</th>
<th>$row2[3]</th>
<th>Date</th>
<th>$row2[4]</th>
<th>Cost</th>
<th>$row2[5]</th>
<th>Email</th>
<th><a href='mailto:".$row2[6]."'>$row2[6]</a></th>
</tr>";
}

Add Numbers to MySQL, HTML table in order [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I will try my best to explain what I am trying to do. Hopefully you can help me out. I have a database that holds links, these links are displayed in a table. I have the entries output properly in order from Points, but I am trying to add a rank number to the side so it says 1, 2, 3, 4, etc going down the page per entry.
Here is my attempt.
<table width = "1000" style='table-layout:fixed;'>
<tr>
// These are the numbers I need to add
<th>Rank</th>
// All these work fine.
<th>Host</th>
<th>Location</th>
<th>Points</th>
</tr>
<?php while($row1 = mysqli_fetch_array($result1)):;?>
<tr>
<td><?php echo $row1[0]; ?></td>
<td><?php echo $row1[1]; ?></td>
<td><?php echo $row1[2]; ?></td>
</tr>
<?php endwhile; ?>
</table>
Hopefully you understand what I am trying to do, if you need any more information let me know.
Thanks for your time.
you mean? :
<?php $rankId=0; while($row1 = mysqli_fetch_array($result1)){ ?>
<tr>
<td><?=$rankId++ ?></td>
<td><?=$row1[0] ?></td>
<td><?= $row1[1] ?></td>
<td><?=$row1[2] ?></td>
</tr>
<?php } ?>

PHP parse error T_FOREACH [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am trying to create table in PHP using array but I am getting parse error in my foreach line. Don't know why its giving me syntax error.
$message = '<table border=1>
<tr>
<th><b>Order Details</b></th>
</tr>
'.foreach ($json_array->request->list as $value) {
$wineId = $value->wineId;
$wineName = $value->wineName;
$noOfDrinks = $value->noOfDrinks;
.'
<tr>
<td>ID</td><td>'.$wineId.'</td>
</tr>
<tr>
<td>Name</td><td>'.$wineName.'</td>
</tr>
<tr>
<td>Quantity</td><td>'.$noOfDrinks.'</td>
</tr>
'. } .'
</table>';
Try this, use string concatenation except php code
$message = '<table border=1>
<tr>
<th><b>Order Details</b></th>
</tr>';
foreach ($json_array->request->list as $value) {
$wineId = $value->wineId;
$wineName = $value->wineName;
$noOfDrinks = $value->noOfDrinks;
$message .= '<tr>
<td>ID</td><td>'.$wineId.'</td>
</tr>
<tr>
<td>Name</td><td>'.$wineName.'</td>
</tr>
<tr>
<td>Quantity</td><td>'.$noOfDrinks.'</td>
</tr>';
}
$message .='</table>';

Why not close row? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I output data from atabase in table.
In result table created with next code:
while($i=$res2->fetch_assoc()) {
$a++;
$t2.='
<tr>
<td>'.$a.'</td>
<td>'.date_format(new DateTime($i['date']),'d.m.Y').'</td>
';
if($valid!='id'){
$t2.='
<td>'.$partner.'</td>
';
}
$t2.='
<td>'.$http_referer.'</td>
</tr>';
}
$t1='
<table class="table table-hover table-bordered">
<thead>
<tr>
<th class="column_th_number">№</th>
<th>Date</th>
';
if($valid!='id'){
$t1.='
<th>Partner</th>
';
}
$t1.='
<th></th>
</tr>
<tr>
<td colspane="2">
</td>
</tr>
</thead>
<tbody>
';
$t3='
</tbody>
</table>
';
echo $t1.$t2.$t3;
but in the result I see that last row was not closed (see image):
Tell me please why last row was not closed?
And how can I make this right?
<td>'.date_format(new DateTime($i['date']),'d.m.Y').'</td>
if($valid!='id'){
replace with
<td>'.date_format(new DateTime($i['date']),'d.m.Y').'</td>'; <--- end the string here
if($valid!='id'){
you missed ';
<td>'.$a.'</td>
<td>'.date_format(new DateTime($i['date']),'d.m.Y').'</td>';
if($valid!='id'){
Thanks ALL.
Error was with colspan(value does not match the number of columns).
Thanks all for help

Categories