<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include 'database.php';
$pdo = Database::connect();
$sql = 'SELECT tl_client.first_name, tl_client.last_name, tl_dvd.title, tl_order.start_date
FROM tl_client, tl_dvd, tl_order
WHERE tl_order.dvd_id = tl_dvd.id AND tl_order.client_id = tl_client.id ';
$rented = ($_POST['rented'] == 'YES')?'YES':'NO';
$sql ='UPDATE tl_order SET active = 1 WHERE id = tl_order.id';
foreach ($pdo->query($sql) as $row) {
echo '<tr>';
echo '<td>'. $row['first_name'] . '</td>';
echo '<td>'. $row['last_name'] . '</td>';
echo '<td>'. $row['title'] . '</td>';
echo '<td>'. $row['start_date'] . '</td>';
echo '<td>' <input type="checkbox" name="rented" value="YES" />'</td>'
echo '</tr>';
}
Database::disconnect();
?>
im trying to update my data using a checkbox. It needs to change the value "active" from 0 to 1" when the checkbox has been clicked.
That means that the content should be gone until later when you return it it becomes in store again. (delete but without real delete).
There's some screenshots from my databases in mysql and also the php code below:
Would really appreciate some help.
Thanks
Related
This is what my table currently looks like:
This is the corresponding PHP code:
<?php
//include 'database.php';
$pdo2 = Database::connect();
$sql2 = "SELECT id,
full_name,
owner_name awardee,
owner awardee_email,
(select concat(user_name,' ',user_last_name) from users where email = who_created) awarder,
creation_time
FROM awards, award_types
where who_created = ? and awards_type=type_id";
$q2 = $pdo->prepare($sql2);
$q2->execute(array($_COOKIE["email"]));
$date = date('Y-m-d', strtotime($date));
foreach ($q2 as $row) {
echo '<tr>';
echo '<td>'. $row['id'] . '</td>';
echo '<td>'. $row['full_name'] . '</td>';
echo '<td>'. $row['awardee'] . '</td>';
echo '<td>'. $row['awardee_email'] . '</td>';
echo '<td>'. $row['awarder'] . '</td>';
echo '<td>'. $row['creation_time'] . '</td>';
echo '<td><a class="btn" href="DeleteAward.php?id='.$row['id'].'">Delete Award</a></td>';
echo '</tr>';
}
Database::disconnect();
?>
I want to only display the date, not time, under the "Date" column. I read from other posts that I need to use some sort of date(creation_time) or DATE_FORMAT(creation_time) command, but I tried both and they just make my "Date" column blank.
I suspect that I'll need to change the echo '<td>'. $row['creation_time'] . '</td>'; line as well, but I was not able to find any guidelines on how to do so. Any help would be greatly appreciated!
There's two ways to go about it:
The MySQL way:
SELECT DATE(creation_time) AS creation_time
Or the PHP way:
$creation_date = date('Y-m-d', strtotime($row['creation_time']));
Edit Here's the exact code for each way:
Mysql:
$sql2 = "SELECT id,
full_name,
owner_name awardee,
owner awardee_email,
(select concat(user_name,' ',user_last_name) from users where email = who_created) awarder,
DATE(creation_time) AS creation_time
FROM awards, award_types
where who_created = ? and awards_type=type_id";
And PHP version:
foreach ($q2 as $row) {
echo '<tr>';
echo '<td>'. $row['id'] . '</td>';
echo '<td>'. $row['full_name'] . '</td>';
echo '<td>'. $row['awardee'] . '</td>';
echo '<td>'. $row['awardee_email'] . '</td>';
echo '<td>'. $row['awarder'] . '</td>';
$creation_time = date('Y-m-d', strtotime($row['creation_time']));
echo '<td>'. $creation_time . '</td>';
echo '<td><a class="btn" href="DeleteAward.php?id='.$row['id'].'">Delete Award</a></td>';
echo '</tr>';
}
I am creating a table by echoing results out as the following:
include 'database.php';
$pdo = Database::connect();
$sql = 'SELECT * FROM kayitlar ORDER BY id DESC';
foreach ($pdo->query($sql) as $row)
{
echo '<tr>';
echo '<td>'. $row['model'] . '</td>';
echo '<td>'. $row['problem'] . '</td>';
echo '<td>'. $row['work'] . '</td>';
echo '<td>'. $row['result'] . '</td>';
echo '<td>'. $row['keywords'] . '</td>';
echo '<td>'. $row['addedby'] . '</td>';
echo '<td>'. $row['date_time'] . '</td>';
echo '<td>'. $row['document'] . '</td>';
}
I allowed users to add documents and the file name is being recorded into documents after string operations. I want to display respective documents as hyperlinks. If I was using mysql_fetch array I would use
<td> view </td>
but I am not good at PDO and getting synthax error everytime.
here is my erroneous code:
echo '<td>'. view file.'</td>';
simply try echo '<td>view file</td>';
Your echo statement mixes inline html with echo. You should use inline html or echo a string, but not both at the same time
echo '<td>view file</td>';
or
<td>view file</td>
echo '<td>view file</td>';
Please can someone review this code and tell me how to get the content of <td> table clickable?
<?php
include 'database.php';
$pdo = Database::connect();
$sql = 'SELECT * FROM products ORDER BY product_id DESC';
foreach ($pdo->query($sql) as $row) {
echo '<tr>';
echo '<td>'. $row['cat_id'] . '</td>';
echo '<td>'. $row['brand_id'] . '</td>';
echo '<td>'. $row['product_title'] . '</td>';
echo '<td>'. $row['product_img1'] . '</td>';
echo '</tr>';
}
Database::disconnect();
?>
What I want is to make by example $row['brand_id'] a link that redirect to the brand details.
Your TD has to have a hyperlink in it.
echo '<td>'. $row['brand_id']. '</td>';
with URL?brand_id=... being the URL of the page with the brand details, where you pass your brand_id into.
So i've been trying to get one record and edit it by pressing the button that is created in that table, but honestly, i have no idea how to do that. Dx Can anyone help me with this? (Yes, i want the button created for each record. You know, so at the end of every row in the table, every record will have it's own button.)
while($rArt = mysqli_fetch_array($sql)){
echo '<tr><td>' . $rArt['ArtID'] . '</td>';
echo '<td>' . $rArt['FiliaalID'] . '</td>';
echo '<td>' . $rArt['Productnaam'] . '</td>';
echo '<td>' . $rArt['Inkoopprijs'] . '</td>';
echo '<td>' . $rArt['Voorraad'] . '</td>';
echo '<td>' . $rArt['Min_voorraad'] . '</td>';
$voo = $rArt['Voorraad'];
$minvoo = $rArt['Min_voorraad'];
$nodig = $minvoo * 2 - $voo;
$chosen = $rArt['ArtID'];
echo '<td>' . $nodig . '</td>';
echo '<td><input type="submit" name="bestel" value="Bestel"></td></tr>';
if(isset($_GET['bestel'])){
$query = mysqli_query($mysql, "
UPDATE artikel a, voorraad v
SET v.voorraad = v.voorraad + '$nodig'
WHERE a.artid = v.artid
AND v.voorraad = '$chosen'");
}
}
I wouldn't use submit in this case, but just a suggestion:
Why don't you try it this way:
<table>
<tr>
<td>Artikel ID</td>
<td> **<a href="bestelpagina/edit/id/1">** </td>
</tr>
</table>
So you can create an action called Edit in which you can do the changes.
Read the comment in the solution as they are important.
while($rArt = mysqli_fetch_array($sql)){
// echo '<tr><td>' . $rArt['ArtID'] . '</td>';
//The above line i removed and added the line below
echo '<tr><td>' .'<a href=\'admin.php?ArtID='.$rArt['ArtID'].'\'>'.$rArt['ArtID'] .'</td>';
echo '<td>' . $rArt['FiliaalID'] . '</td>';
echo '<td>' . $rArt['Productnaam'] . '</td>';
echo '<td>' . $rArt['Inkoopprijs'] . '</td>';
echo '<td>' . $rArt['Voorraad'] . '</td>';
echo '<td>' . $rArt['Min_voorraad'] . '</td>';
$voo = $rArt['Voorraad'];
$minvoo = $rArt['Min_voorraad'];
$nodig = $minvoo * 2 - $voo;
$chosen = $rArt['ArtID'];
echo '<td>' . $nodig . '</td>';
//echo '<td><input type="submit" name="bestel" value="Bestel"></td></tr>';
//removed this as you dont need input button here.
}///Your while loop should close here not in the ent
if(isset($_GET['bestel'])){
$query = mysqli_query($mysql, "
UPDATE artikel a, voorraad v
SET v.voorraad = v.voorraad + '$nodig'
WHERE a.artid = v.artid
AND v.voorraad = '$chosen'");
}
//} I remove this tag as your while loop should close before isset function
I have mysql table with following columns :
no, name, oname, quantity
I have n number of records in the tables ,I want to fetch these records in an html table that dynamically increases'decreases its row length according to the number of rows in mysql database. I am trying following but its not working.can anyone help me out here
<?php
include './connection.php';
$query = "select * from orderdetails";
$result = mysql_query($query);
echo '<table border="1" style="width:600px" align=center >';
echo '<tr bgcolor="lavendar">';
echo '<td width="15%">Order No.</td>';
echo '<td>Name</td>';
echo '<td>Order</td>';
echo '<td>Quantity</td>';
echo '</tr>';
echo '</table>';
while( $row = mysql_fetch_assoc($result)){
echo '<tr>';
echo '<td>' row['no'] '</td>';
echo '<td>' row['name'] '</td>';
echo '<td>' row['oname'] '</td>';
echo '<td>' row['quantity'] '</td>';
echo '</tr>';
}
echo '</table>';
?>
Where you are printing out your values, there are a few errors.
In this specific code block:
while( $row = mysql_fetch_assoc($result)){
echo '<tr>';
echo '<td>' row['no'] '</td>';
echo '<td>' row['name'] '</td>';
echo '<td>' row['oname'] '</td>';
echo '<td>' row['quantity'] '</td>';
echo '</tr>';
}
First off all, you would want to concatinate your strings, PHP uses . for that.
For example, to concatinate "World!" to "Hello, ", to print out Hello, World!, you would use the following:
echo "Hello, " . "World!";
You are also missing a variable sign ($) in your code, when printing out the rows.
In your case, you're using echo '<td>' row['no'] '</td>';,
where it should have been echo '<td>' . $row['no'] . '</td>';
To clarify, your code should look like this:
while($row = mysql_fetch_assoc($result)){
echo '<tr>';
echo '<td>' . $row['no'] . '</td>';
echo '<td>' . $row['name'] . '</td>';
echo '<td>' . $row['oname'] . '</td>';
echo '<td>' . $row['quantity'] . '</td>';
echo '</tr>';
}
Relevant PHP documentation:
PHP String Concatination
Echo documentation
There's a typo-
row['no']
to
$row['no']
Similarly other variables too.