In my loop I have a link that sends the ID via a query string, however I want to do it through AJAX. I've attempted to do this through setting the PHP variable to a JS variable and haven't had much success. Everything I try says illegal token.
(It's on the 8th line).
<?php
//We display the list of read messages
while($dn2 = mysql_fetch_array($req2))
{
?>
<tr>
<td class="left"><?php echo htmlentities($dn2['title'], ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo $dn2['reps']-1; ?></td>
<td><?php echo htmlentities($dn2['username'], ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo date('Y/m/d H:i:s' ,$dn2['timestamp']); ?></td>
</tr>
<?php
}
You have way to many quotes going on here. I've cleaned it up below.
<?php
//We display the list of read messages
while($dn2 = mysql_fetch_array($req2))
{
?>
<tr>
<td class="left"><?php echo htmlentities($dn2['title'], ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo $dn2['reps']-1; ?></td>
<td><?php echo htmlentities($dn2['username'], ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo date('Y/m/d H:i:s' ,$dn2['timestamp']); ?></td>
</tr>
<?php
}
You have too many quotes. Combining "' will cause you problems.
<td class="left"><?php echo htmlentities($dn2['title'], ENT_QUOTES, 'UTF-8'); ?></td>
I think there is a typo:
you are writing $dn1['id'] instead of $dn2['id']
But that could be another problem. As others have pointed out, the problem seems to be your use of quotes.
Where is $dn1 coming from? I only see $dn2
Related
I have a CSV file that contains books, the columns in it are:
book_id,name, date_published
I need to put this data into an HTML table using PHP, then use javascript to add a search function, that makes it so that if the rows match with the input only then will the table be visible?
I'm completely stumped and would appreciate an easy understanding of the solution!
well I tried to import the CSV file in PHP but I can't seem to get it into an array
I tried other methods some got me to the javas cript bit but nothing successful
You can open your CSV file and display it in a table as follows:
<?php
// Open the CSV file
$fcsv = fopen( 'filename.csv', 'r' );
// Get header row
$row = fgetcsv( $fcsv );
// Output start of table & header row
?>
<table>
<thead>
<tr>
<td><?= $row[0] ?></td>
<td><?= $row[1] ?></td>
<td><?= $row[2] ?></td>
<td><?= $row[3] ?></td>
<td><?= $row[4] ?></td>
<td><?= $row[5] ?></td>
<td><?= $row[6] ?></td>
</tr>
</thead>
<tbody>
<?php
// Loop through rest of rows in CSV
while ( ( $row = fgetcsv( $fcsv ) ) !== false )
{
?>
<tr>
<td><?= $row[0] ?></td>
<td><?= $row[1] ?></td>
<td><?= $row[2] ?></td>
<td><?= $row[3] ?></td>
<td><?= $row[4] ?></td>
<td><?= $row[5] ?></td>
<td><?= $row[6] ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
For the Javascript filtering, you should look at the DataTables JavaScript plugin... it's very simple to set up (see examples on the website) and can search, order & filter data in a variety of ways depending on your needs.
<?php if($result["staff_follow"]== 'By Party'&& $result["Status"]== 'PENDING'): ?> style="background-color:#E99E3E;
the below feiled is not working.
"onmouseover="this.bgColor='litegreen'" onmouseout="this.bgColor='#E99E3E'"
<?php elseif($result["Status"]== 'PENDING'): ?>style= "background-color:#DB7093; "
<?php endif; ?> >
<!-- <td><?php echo $result["Roll_No"];?></td> -->
<td style="text-align: center;"><?php echo $counter ;?></td>
<td><?php echo $result["Document_Name"];?></td>
<td><?php echo $result["Document_Num"];?></td>
<td><?php echo $result["Extent"];?></td>
<td><?php echo $result["Status"];?></td>
<td><?php echo $result["Document_App_Det"];?></td>
<td><?php echo $result["staff_follow"];?></td>
Try again with this.bgColor='LightGreen'.
The named colors can be found here:
https://htmlcolorcodes.com/color-names/
i need help. i have a table that i need to view the data of the user that already doing report. when the technician update the form, user can know who is the responsible person for their report. upon update the technician will send the id to the database but the problem is the user will see the id when they check the report. i need to change the id to the technician name.
<tr bgcolor="#00aeef">
<td>Tarikh</td>
<td>Staff ID</td>
<td>Kerosakan</td>
<td>Nyatakan</td>
<td>Maklumat Kerosakan</td>
<td>Lokasi Kerosakan</td>
<td>Nama Pegawai</td>
<td>Status</td>
<td>Catatan</td>
</tr>
<?php include('../dbcon.php');
$username=$_SESSION['username'];
$username_view=$_SESSION['username_view'];
$qry=mysql_query("SELECT * FROM aduan_form where staff_id='$username' ORDER BY tarikh DESC") or die(mysql_error());
?>
<?php while ($row_view = mysql_fetch_array($qry)){ ?>
<?php if ($totalRows_view > 0) { // Show if recordset not empty ?>
<?php } // Show if recordset not empty ?>
<tr>
<td><?php echo $row_view['tarikh']; ?></td>
<td><?php echo $row_view['staff_id']; ?></td>
<td><?php echo $row_view['kerosakan']; ?></td>
<td><?php echo $row_view['nyatakan']; ?></td>
<td><?php echo $row_view['m_kerosakan']; ?></td>
<td><?php echo $row_view['tempat_rosak']; ?></td>
<td><?php echo $row_view['nama_pegawai']; ?></td>
<td><?php echo $row_view['status']; ?></td>
<td><?php echo $row_view['catatan']; ?></td>
<?php } while ($row_view = mysql_fetch_assoc($view)); ?></tr>
</table>
here is my current code.
i do try to put some code that will allow the id to change to the name but it view the same name and it is even in the table that is still not been update.
<?php include('../dbcon.php');
$username=$_SESSION['username'];
$username_view=$_SESSION['username_view'];
$qry1=mysql_query("SELECT * FROM login,aduan_form where aduan_form.nama_pegawai=login.username ORDER BY aduan_form.tarikh DESC") or die(mysql_error());
?>
<?php while ($row_view1 = mysql_fetch_array($qry1)){ ?>
how should i do to make it right? i need the table to view the right technician name based on the right id and also display the name only in the table that already been update.
Hope I got your database schema right. So you can query like:
$qry1=mysql_query("
SELECT aduan_form.*, login.username
FROM aduan_form
LEFT JOIN login
ON login.id = aduan_form.staff_id
WHERE aduan_form.nama_pegawai=login.username
ORDER BY aduan_form.tarikh DESC")
or die(mysql_error());
and change your html output to something like:
...
<td><?php echo $row_view['tarikh']; ?></td>
<td><?php echo $row_view['username']; ?></td>
<td><?php echo $row_view['kerosakan']; ?></td>
...
I got the following php foreach loop in the A page of my web appliation. And i want to use the $watson variable which is inside this loop in an other php B page. What i did is used this variable as a value in an extra input button:<input type="button"/ value="<?php echo $watson; ?>,so to be able to capture this var in javascript like you see below.
<tbody>
<?php
foreach($records as $r) {
$watson = $r->case_reference;
?>
<tr>
<td><?php echo escape($r->user); ?></td>
<td><?php echo escape($r->customer); ?></td>
<td><?php echo escape($r->vessel); ?></td>
<td><?php echo escape($r->country); ?></td>
<td><?php echo escape($r->port); ?></td>
<td><?php echo escape($r->eta); ?></td>
<td><?php echo escape($r->service_station); ?></td>
<td><?php echo escape($r->type_of_service); ?></td>
<td><?php echo escape($r->case_reference); ?></td>
<td><?php echo escape($r->status); ?></td>
<td><input type="button" value="<?php echo $watson; ?>" onclick="popEdit(this.value);" /></td>
</tr>
<?php
}
?>
</tbody>
The code for the onclick="popEdit(this.value);"function which pops up the B page mentioned above is :
function popEdit(str) {
window.open("example.php?watson="+str, "pop_edit_jobs",
"width=400,height=350,scrollbars=no,left=460,top=400")
}
And the php B page code starts as $ref_num = $_GET['watson']; so i can use the variable.
My problem is that i dont want the input/button in the A page to show the variable on it instead i want it to just show the word EDIT.But to do that i ll have to change its value and then i wont be able to capture this $watson var in javascript.
Any suggestions regarding how to achieve the above effect?
<td><input type="button" value="EDIT" onclick="popEdit('<?php echo $watson; ?>');" /></td>
should achieve the desired effect.
Wrap a form around your entire table, then use submit buttons:
<input type="submit" name="watson" value="<?php echo htmlspecialchars($watson); ?>" />
I need some help.
I used echo to display the ID but after I click each ID, the popup window appeared and will display the same page for all ID. I want to display a different page for each ID. How can I solve this? Thank you..
<td><a href="d1.php" onClick="javascript:void
window.open('d1.php','1382580890418','width=800,height=600,toolbar=1,menubar=1,location=1,s
tatus=1,scrollbars=1,resizable=1,left=0,top=0');return false;"><?php echo $row["ID"];
?></a></td>
<td><?php echo $row["NO"]; ?></td>
<td><?php echo $row["CATEGORY"]; ?></td>
<td><?php echo $row["TYPE"]; ?></td>
<td><?php echo $row["BRAND"]; ?></td>
<td><?php echo $row["MODEL"]; ?></td>
<td><?php echo $row["SERIAL"]; ?></td>
<td><?php echo $row["YEAR"]; ?></td>
<td><?php echo $row["DUEDATE"]; ?></td>
<td><?php echo $row["REGION"]; ?></td>
<td><?php echo $row["STATUS"]; ?></td>
Try with passing different name every row like :
<td>
<?php echo $row["ID"]; ?>
</td>
Different window name for every row by passing the row id as window names.
Ideally all rows should be handled by single window, by setting your logic at d1.php, but I still this can be a solution.