Home > Archive > PHP SQL > August 2006 > Adding a DELETE/UPDATE option to my results
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Adding a DELETE/UPDATE option to my results
|
|
| mpar612@gmail.com 2006-08-07, 6:58 pm |
| Hi everyone,
My code is posted below. I am trying to add update and delete buttons
at the end of each row returned from the database. I understand the
use of the DELETE and UPDATE query, but I'm about how to
implement them in my code using PHP. I searched multiple forums and
made an attempt in lines 5 and 6 to try to implement the DELETE
feature, but I'm sort of lost. Any help or tips would be greatly
appreciated. Thanks in advance!
<?php
// Access the global variable $db inside this function
global $db;
$delete = 'DELETE FROM lounge WHERE isbn = $ROW['isbn']';
$del_query = $db->($delete);
// build up the query
$sql = 'SELECT isbn, artist_name, album_title,
date_format(release_date, '%M %d, %Y') as release_date,
date_format(add_date, '%M %d, %Y') as add_date, description, price
FROM lounge';
// Send the query to the database program and get all the rows back
$results = $db->getAll($sql);
print '<table border='1' cellspacing='0'
cellpadding='0'>';
print '<tr><th>ISBN</th><th>Artist Name</th><th>Album
Title</th><th>Release
Date</th><th>Description</th><th>Price</th><th>Date
Added</th><th>Update</th><td>Delete</th></tr>';
foreach ($results as $res) {
printf('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',
htmlentities($res->isbn),
htmlentities($res->artist_name),
htmlentities($res->album_title),
htmlentities($res->release_date),
htmlentities($res->description),
htmlentities($res->price),
$res->add_date,
)
;
}
?>
| |
| ZeldorBlat 2006-08-07, 6:58 pm |
|
mpar612@gmail.com wrote:
> Hi everyone,
>
> My code is posted below. I am trying to add update and delete buttons
> at the end of each row returned from the database. I understand the
> use of the DELETE and UPDATE query, but I'm about how to
> implement them in my code using PHP. I searched multiple forums and
> made an attempt in lines 5 and 6 to try to implement the DELETE
> feature, but I'm sort of lost. Any help or tips would be greatly
> appreciated. Thanks in advance!
>
> <?php
>
> // Access the global variable $db inside this function
> global $db;
>
> $delete = 'DELETE FROM lounge WHERE isbn = $ROW['isbn']';
> $del_query = $db->($delete);
>
>
> // build up the query
> $sql = 'SELECT isbn, artist_name, album_title,
> date_format(release_date, '%M %d, %Y') as release_date,
> date_format(add_date, '%M %d, %Y') as add_date, description, price
> FROM lounge';
>
> // Send the query to the database program and get all the rows back
> $results = $db->getAll($sql);
>
> print '<table border='1' cellspacing='0'
> cellpadding='0'>';
> print '<tr><th>ISBN</th><th>Artist Name</th><th>Album
> Title</th><th>Release
> Date</th><th>Description</th><th>Price</th><th>Date
> Added</th><th>Update</th><td>Delete</th></tr>';
> foreach ($results as $res) {
> printf('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',
> htmlentities($res->isbn),
> htmlentities($res->artist_name),
> htmlentities($res->album_title),
> htmlentities($res->release_date),
> htmlentities($res->description),
> htmlentities($res->price),
> $res->add_date,
> )
> ;
> }
> ?>
Trying echo'ing out the delete query:
$delete = 'DELETE FROM lounge WHERE isbn = $ROW['isbn']';
echo $delete
And see what you get. You'll probably get exactly what you see above
since PHP variables are not parsed inside single-quoted strings. Try
this instead:
$delete = "DELETE FROM lounge WHERE isbn = {$ROW['isbn']}";
$del_query = $db->($delete);
| |
| mpar612 2006-08-07, 6:58 pm |
| ZeldorBlat wrote:
> mpar612@gmail.com wrote:
>
> Trying echo'ing out the delete query:
>
> $delete = 'DELETE FROM lounge WHERE isbn = $ROW['isbn']';
> echo $delete
>
> And see what you get. You'll probably get exactly what you see above
> since PHP variables are not parsed inside single-quoted strings. Try
> this instead:
>
> $delete = "DELETE FROM lounge WHERE isbn = {$ROW['isbn']}";
> $del_query = $db->($delete);
Thanks, now how do I print that to the browser to test it? I have a
foreach loop printing out all of the rows in my database. My current
printf function is confusing me right now. Should I use something else
to print this? Thanks!
|
|
|
|
|