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 9 years ago.
Improve this question
I have table and i know how to do most of the echo strings, BUT when i get a long one that include words, and headings i get lost. So how do i convert this line?
<a class="signUpButton" href="#">Sign Up</a>
Take this line and get it to work in the below code which is only partial code.
echo "<tr>";
echo "<td>" . $row->name . "</td>";
echo "<td>" . $row->monthly . "</td>";
echo "<td>" . $row->annually . "</td>";
echo "</tr>";
echo "</tr>";
}
echo "</tbody>";
echo "<tfoot>";
echo "<tr>";
echo "<td>";
echo "<a class='signUpButton','href='#'>";
echo "</a>";
echo "</td>";
echo "<td>";
echo "<a class='signUpButton','href='#'>";
echo "</a>";
echo "</td>";
echo "<td>";
echo "<a class='signUpButton','href='#'>";
echo "</a>";
echo "</td>";
echo "</tr>";
echo "<tfoot>";
This code here is what i have now.
echo "<a class='signUpButton','href='#'>";
it does not work either so something is up. only part that works is everything from the echo to the ',' it closes fine, im just not able to see my mouse pointer show that indeed it is a link..
P.S. this code above is only a section, the table is huge, and is working except for the minor issues i am having with links and displaying the button words "signup"
I'm not quite sure what you're asking, but if you need to echo out:
<a class="signUpButton" href="#">Sign Up</a>
then use:
echo '<a class="signUpButton" href="#">Sign Up</a>';
or:
echo "<a class=\"signUpButton\" href=\"#\">Sign Up</a>";
The first method uses single quotes in the echo statement allowing the use of double quotes inside
The second method uses double quotes for the echo statement so uses a \ character to escape the " inside the echo so it doesn't close it.
Related
I'm trying to create a button for each row in my database that, when pressed, will delete this particular row. I should also mention that the data from the database is displayed correctly and the table I'm using is also completely fine.The buttons appear at the side of each row, when the button is clicked, the row dissapears but the data is not deleted from the database, when the page is reloaded the rows that were previously "deleted", reappear. After pressing the button i also get this "Fatal error: Uncaught Error: Call to undefined function mysql_query() in C:\xampp\htdocs\INDUSTRIALPROJECT\records.php:56 Stack trace: #0 {main} thrown in C:\xampp\htdocs\INDUSTRIALPROJECT\records.php on line 56".
line 56 is : $del = mysql_query("DELETE FROM records WHERE id=" . $row['id']);. The same query works fine when placed directly into phpMyAdmin.
<?php
// Check connection
include_once 'config.php';
if ($link->connect_error) {
die("Connection failed: " . $link->connect_error);
}
$sql = "SELECT * FROM records";
$result = $link->query($sql);
function post($key){ return(isset($_POST[$key]) ? htmlspecialchars($_POST[$key]) : ""); }
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
if(post('rowButton'.$row['id']) =="Delete"){
$del = mysql_query("DELETE FROM records WHERE id=" . $row['id']);
$deleted = '<p>Entry ' . $row['id'] . ' was succesfully deleted</p>';
}
else {
echo '<form action ="' . $_SERVER['PHP_SELF'] . '" method="post">';
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row["visitingdate"]. "</td>";
echo "<td>" . $row["department"] . "</td>";
echo "<td>" . $row["visitingreason"]. "</td>";
echo "<td>" . $row["importance"]. "</td>";
echo "<td>" . $row["visitorname"]. "</td>";
echo "<td>" . $row["company"]. "</td>";
echo "<td>". $row["internalrecipientname"]. "</td>";
echo "<td>". $row["visitinglocation"]. "</td>";
echo "<td>". $row["ETA"]. "</td>";
echo "<td>". $row["ETD"]. "</td>";
echo "<td>". $row["HRverification"]. "</td>";
echo "<td>". $row["visitcompleted"]. "</td>";
echo '<td><input type="submit" name="rowButton'. $row['id'] .'" value="Delete"/> </td>';
echo "</tr>";
echo "</form>";
}
}
echo "</table>";
echo $deleted;
}
else { echo "0 results"; }
$link->close();
?>
First, this appears to be rather vulnerable to SQL injection attacks. StackOverflow is quite font of pointing this out up front, because it's really a solved problem that you should account for in the early stages of development. You're taking untrusted data (that was submitted by the user, without sanitizing it) and putting it directly in an SQL query. Bad things can happen when that occurs. Now with that aside, on to your actual question.
"Nothing happens" means the page doesn't change at all, right? So the browser doesn't know what to do when the button is clicked.
I think you haven't put any <form...> declaration here, which would be required for <input type="submit"> to do anything useful. You could use JavaScript with the stand alone submit button, but I don't see that in your code, either. You'll need something to tell the browser what to do when the submit button is pressed.
I haven't really tested the rest of your code, but based on what you've got already you might add the following:
else {
+ echo '<form action ="' . $_SERVER['PHP_SELF'] . '" method="post">';
echo "<tr>";
and
echo "</tr>";
+ echo "</form>";
}
(don't add the plus sign, that's just to show which line is added). I should add that I don't usually use submit buttons like this, so there's a chance I missed some additional details about how you're calling this, but putting the form in a <form> tag is at least a good start.
Edit
The mysql_query() function was removed in PHP 7; if you're using an older PHP you need to add support for the MySQL functions or if you're on PHP 7, you should use the MySQLi or PDO_MySQL functions instead. The warning box on the PHP manual page for mysql_query has some links for alternatives, how to select an alternative, and other supporting documentation that may help you. This StackOverflow answer may help, as well.
So for a school project, I'm making an inventory system, one of the pages contains a table with all the available stock. But there is way too much data to display in the table and I don't want the table to be 300 records long. So i decided I wanted to implement pagination on the already existing table. Now the thing is that I have no idea where to begin. I'm doing this with Object-oriented PHP. I hope someone can send me into the right direction of where to begin.
PHP code where i fill my table with data:
<?php
require_once('classes/Database.php');
$db = new Database;
$query = $db->query("SELECT * FROM producten");
$count = $query->rowCount();
if($count > 0) {
while($row = $query->fetch())
{
echo "<tr>";
echo "<td id='td1'>" . $row[0] . "</td>";
echo "<td id='td2'>" . $row[1] . "</td>";
echo "<td id='td3'>" . $row[2] . "</td>";
echo "<td id='td4'>" . $row[3] . "</td>";
echo "<td id='td4'>" . $row[4] . "</td>";
echo "<td id='td5'><a onclick='document.getElementById(\"id\").value=".$row[0]."' data-toggle='modal' data-target='#exampleModal' href=''><img data-toggle='tooltip' data-id='$row[0]' data-placement='top' title='Edit' src='img/edit.svg' height='25'></a></td>";
echo "<td id='td6'><a id='btn_link' href='php/Delete.php?id=".$row[0]."'><img data-toggle='tooltip' data-placement='top' title='Delete' src='img/delete_2.svg' height='25'></a></td>";
//echo "<td id='td5'><button type='button' class='btn btn-danger'>Delete</button></td>";
echo "</tr>";
}
}
?>
Then in my HTML file, I just include this PHP file so it's being displayed on the page.
Try using jQuery DataTables https://datatables.net/, its very easy and useful for handle many record and support Server-side processing .
You can use Bootstrap datatable with zero configuration.
Here is the link
You can easily configure as per your preferences and requirements. Go through the docs they are easy to understand.
Other way would be:
Use Mysql query with limit and offset but that would be another long way around though.
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
I'm getting data from a database and inserting it into this table.
while (($result_row = $result->fetch_assoc()) !== NULL) {
echo "<tr>";
echo "<td>", $result_row['title'], "</td>";
echo "<td>", $result_row['author'], "</td>";
echo "<td>", $result_row['isbn'], "</td>";
echo "<td>", $result_row['price'], "</td>";
echo "</tr>";
}
I can't seem to figure out how to print an actual $ for the price. Any suggestions?
echo "<td>\$", $result_row['price'], "</td>";
or better yet, use money_format() http://php.net/manual/en/function.money-format.php
echo "<td>$", $result_row['price'], "</td>";
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
i want to apply css for a while looping but it returns only the first data if i use css , and without css it returns all the data normally. here is my code it's simple.
$users=mysql_query("select * from users");
while($user=mysql_fetch_array($users))
{
echo "<table>";
echo "<tr>";
echo "<td class='user'>";
echo $user['pseudo'];
echo "</tr>";
echo "</td>";
echo "</table>";
}
Your problem is position:fixed. This tells the browser to lay all tables, one over the other, at window position right:500; left:500; top:100;. So, everything is there, but you tell the browser to put each new data set into a new table, and stack it in front of or behind the previous dataset (=table).
My best guess as to what you wanted to achieve is
$users=mysql_query("select * from users");
echo "<table>";
while($user=mysql_fetch_array($users))
{
echo "<tr>";
echo "<td class='user'>";
echo $user['pseudo'];
echo "</td>";
echo "</tr>";
}
echo "</table>";
$users=mysql_query("select * from users");
echo "<table>";
while($user=mysql_fetch_array($users))
{
echo "<tr>";
echo "<td class='user'>";
echo $user['pseudo'];
echo "</td>";
echo "</tr>";
}
echo "</table>";
Your HTML was malformed before. The tr was closed, before the td was (<tr><td></tr></td>) which is invalid. Also it makes more sense to wrap the loop in the table, instead of declaring it in every iteration.
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 querying my database and dumping the data into an HTML table. One of my database keys is called "time_expire", with a value of -1 meaning never. Therefore, to show something to the effect of "never" in the HTML table instead of the raw data I am attempting to change the variable before it is echo'd.
This is my code
<?php
$sql = "SELECT * FROM penalties ORDER BY id DESC";
$result = mysql_query($sql);
while ($rows = mysql_fetch_array($result)) {
if ($rows['time_expire'] = '-1') {
$rows['time_expire'] = '<span class="label label-important">Permanent</span>';
}
echo "<tr>";
echo '<td>' . $rows['id'] . '</td>';
echo "<td>" . $rows['client_id'] . "</td>";
echo "<td>" . $rows['type'] . "</td>";
echo "<td>" . date('m/d/Y', $rows['time_add']) . "</td>";
echo "<td>" . $rows['duration'] . "</td>";
echo "<td>" . $rows['time_expire'] . "</td>";
echo "<td>" . $rows['reason'] . "</td>";
echo "</tr>";
}
?>
This code does not error, however every row in my HTML table has an expiration value of "never", even if the the raw data is different.
This seems to be a common typo in the if statemenet
if ($rows['time_expire'] = '-1') [
^
|
If you want to the interpreter spot these for you, try using yoda conditions like this:
if ('-1' = $rows['time_expire'])
This form will create error however the correct forms both work ok:
'-1' == $rows['time_expire']
or
$rows['time_expire'] == '-1'
I think it is supposed to be:
if ($rows['time_expire'] == '-1')
not
if ($rows['time_expire'] = '-1')
First what type is time_expire?
If time_expire is numeric then you should change the condition to:
if ($rows['time_expire'] == -1) which will evaluate properly.
Secondly your condition checking is actually assigning the value to $rows['time_expire'] with single =, it should be double = like ==.
Try changing If condition to if ($rows['time_expire'] == '-1'). Right now what your condition says that variable $rows['time_expire'] is equal to '-1' which is always returning true.It might get you in the unlimited looping.