I'm creating a site to upload content and I want the user to be able to delete content on their Edit page. The following code is what I have echoed after the user inputs their content
<div id="content_review">
<?php
$q_getRev = "SELECT * FROM REVIEWS ORDER BY RID DESC";
$r_getRev = mysql_query($q_getRev, $connection);
$n_getRev = mysql_num_rows($r_getRev);
for ($i = 0; $i < $n_getRev; $i++) {
echo '<img class="poster" src="'
. mysql_result($r_getRev, $i, 'PREVIEW_IMG') . ' " />';
echo '<div class="title">'
. mysql_result($r_getRev, $i, 'TITLE') . '</div><br/>';
echo '<div class="reviews">'
. mysql_result($r_getRev, $i, 'REVIEW') . '</div>';
echo '<div><img src=image/x.png id="delete">'
. mysql_result($_delRev, $i, 'REVIEW') . '</div>';
}
?>
I want the user to be able to delete content that was previously printed in PHP. I'm not entirely sure how to proceed to make the following line delete content from my REVIEW column from mysql (the following line appears as a delete button next to the already printed content)
echo '<div><img src=image/x.png id="delete">'
. mysql_result($_delRev, $i, 'REVIEW').'</div>';
That line should be:
echo '<div><img src="image/x.png"></div>';
Then you need to write a delete_content.php script that deletes the content whose RID is equal to $_GET['rid']. The PHP in that script should be something like:
$rid = intval($_GET['rid');
$delRev = "DELETE FROM REVIEWS WHERE RID = $rid";
Also notice that I removed the id="remove" attribute from the <img> tag. IDs have to be unique, but you were using the same ID for each item. I doubt you need an ID on the image tags, so I just removed it.
Related
The following is my code:
<?php $result = mysql_query("SELECT * FROM pm_categories WHERE parent_id = 512 ORDER BY tag desc"); ?>
<?php while($row = mysql_fetch_assoc($result)) { ?>
<a class="button button-blue plus20 category" href="https://www.parvizshahbazi.com/ganj_videos/app/listvideos.php?range=<?php echo $row['tag']; ?>"><?php echo str_replace("-", " - ", $row['tag']); ?></a>
<?php } ?>
This is the result:
The buttons have numbers 1-100,101-200 and so on
I was wondering how I can have 801-1000 instead of 801-900. I know that the digits are created from the while loop. Is there anyway to manually create the 801-1000 button?
I tried to manipulate the chart numbers in SQL, yet if 801-900 is manually changed to 801-1000, it gives an error. Because they are in the category of 801-900. What I want is just 801-1000 on the button for 801-1000.
Here is my SQL 'pm_config':
pm_config list
In sum, this is what I want in the end (it is photo-shopped):
What I desire to have in the end
You could, in your 'while' loop, create a specific rule, like this:
while($row = mysql_fetch_assoc($result))
{
// if your loop is treating the 801-900 tag, then just change it to 801-1000
if($row['tag'] == '801-900') { $row['tag'] = '801-1000'; }
echo '<a class="button button-blue plus20 category" href="https://www.parvizshahbazi.com/ganj_videos/app/listvideos.php?range=' . $row['tag'] . '">' . str_replace("-", " - ", $row['tag']) . '</a>';
}
I have constructed an SQL query to lay out some info on a web page. The query works well. The problem is with each iteration of while loop a CSS class needs to be auto-incremented by 1.
<div class="related-item item1">
'item1' should become 'item2' in the next iteration and so on. Can you give me something ideas how to do it?
<?php
//Construct the SQL query code
$rel = "SELECT entries.*, images.name
FROM entries, images
WHERE entries.id = blog_id
ORDER BY dateposted DESC
LIMIT 0, 3;";
//Send the query to the MySQL server
$result = mysql_query($rel);
//Pull the row as an associative array
while ($row = mysql_fetch_assoc($result)) {
echo '<div class="related-item item1">
<div class="thumbnail-wrapper">';
echo '<img src="./images/' . $row['name'] . '" alt="How SHAPE Reader Caitlin Flora Lost 182 Pounds"/></div>
<h4 class="related-article-title">
' . $row['subject'] . '
</h4>
</div>';
} //End of while loop
?>
Just keep a counter variable going
$cnt = 1;
while(fetch from db) {
echo "<a class='foo{$cnt}'>click me</a>";
$cnt++;
}
which produces
<a class='foo1'>click me</a>
<a class='foo2'>click me</a>
<a class='foo3'>click me</a>
etc...
but generally this sort of thing is NOT necessary for CSS. You'd have to create a css rule for EVERY one of those <a> elements being created, which gets incredibly ugly and repetitive. There is nth-child support in CSS, so you can write rules which "modify" themselves based on which child an element is (1st, 2nd, ... Nth).
Add an integer and increment it...
<?php
//Construct the SQL query code
$rel = "SELECT entries.*, images.name
FROM entries, images
WHERE entries.id = blog_id
ORDER BY dateposted DESC
LIMIT 0, 3;";
//Send the query to the MySQL server
$result = mysql_query($rel);
$i = 1;
//Pull the row as an associative array
while ($row = mysql_fetch_assoc($result)) {
echo '<div class="related-item item{$i}">
<div class="thumbnail-wrapper">';
echo '<img src="./images/' . $row['name'] . '" alt="How SHAPE Reader Caitlin Flora Lost 182 Pounds"/></div>
<h4 class="related-article-title">
' . $row['subject'] . '
</h4>
</div>';
$i++;
} //End of while loop
?>
I need your help in creating a search result page for my site. Its a simple php cms site simply fetching content from mysql.
Using a simple query to fetch search
$search = $_GET["search"];
$search = preg_replace('#[^0-9]#i','',$_GET['search']);
$searchresult = mysql_query ("SELECT * FROM pages WHERE pgcontent LIKE '%$search%'");
while ($row = mysql_fetch_array($searchresult))
{
echo '<h3>' . $row["PageTitle"] . '</h1>';
echo '<p>' . $row["PageContent"] . '</p><br /><br />';
}
What i want to do is not to display the whole page content, just the line where any word matches with the search term ... or just the first few lines of that page where the search term was found.
Friends can you help me in doing this please? it will be a big favor ... thank you
You could run post processing on $row["PageContent"]
Something like
while ($row = mysql_fetch_array($searchresult))
{
echo '<h3>' . $row["PageTitle"] . '</h3>';
$position = strpos($row["PageContent"], $search);
$snippet = substr($row["PageContent"], $position - 100, $position + 100);
echo '<p>' . $snippet . '</p>';
echo '<br /><br />';
}
Where you begin your snippet 100 characters from the beginning of the matched term and end it 100 characters after the beginning of the term. Obviously you tune this to whatever you want but this is the basic idea.
If I missed the point let me know and I may update.
I'm doing a movie library as a school assignment and have list of movies from a database table that I want to have a edit and a delete option next to on each row.
I want to use a edit/delete links for it. Like:
"<a href='moviestorage.php?edit=" . $id . "'>Edit</a>"
But I'm not sure how I can fish up the id for each movie so that it's deleted from the database. What's the query that I should write? Do I need to have a separate delete.php file?
I´m a very newbie so bear with me:)
Below you can see the code that I've done.
<?php
require 'connect.inc.php';
//This feels incomplete... I´m trying here to fish the ID...
$id = "SELECT id from movies";
$query = "DELETE FROM movies WHERE id='$id'";
$query = "SELECT * FROM movies, categories WHERE movies.genre_id = categories.genre_id";
$result = mysql_query($query);
if (!$result) die ("Database access failed:" .mysql_error()) ;
$rows = mysql_num_rows($result);
echo '<table><tr><th>Title</th><th>Release year</th><th>Genre</th><th>Director</th><th>Update</th><th>Delete</th></tr>';
for ($j = 0 ; $j < $rows ; ++$j) {
echo '<tr><td>' . mysql_result($result,$j,'title') . '</td>' ;
echo '<td>' . mysql_result($result,$j,'release_year') . '</td>' ;
echo '<td>' . mysql_result($result,$j,'genre') . '</td>' ;
echo '<td>' . mysql_result($result,$j,'director') . '</td>' ;
echo '<td>'."<a href='edit_movie.php?edit=" . $id . "'>Edit</a>".'</td>' ;
echo '<td>'."<a href='delete.php?delete=" . $id . "'>Delete</a>".'</td></tr>' ;
}
echo '</table>';
include 'add_movie.php';
?>
I would recommend that you use a form for every row with a delete and edit button and a hidden field with the ID. You can then post that form to the right script and determine the action to take there.
If you have to use a link to delete an item, at least have the link lead to another confirmation page with a form that the user has to submit and that posts to your delete script.
if you have to edit and delete on new page than you can put hyperlink this way
echo "<a href=\"edit.php?id=".mysql_result($result,$j,'id')."\"><strong>EDIT</strong>";
echo "<a href=\"delete.php?id=".mysql_result($result,$j,'id')."\"><strong>delete</strong>";
and for conformation for delete you can use this on delete link
echo "<a href=\"delete.php?id=".mysql_result($result,$j,'id')."\" onclick=\"return confirm('You want to delete your own account???');\"><strong>delete</strong>";
than get the id on next page using
$id = $_GET['id'];
hope it will be usefull for you
If you need a simple and effective solution, use datatables. :)
please search in google. spent some time to study how to implement it, it will save a lot of time in future.
I run a website for my church. In a database on the server, we store all of the newest sermons' information so that when a user clicks a button on the first page, the newest sermons will show up in a div. For a long time, everything was working just great, but now, the returned code just doesn't show up.
The weird thing is, if I open the page in Google Chrome and hit "Inspect Element" over the div, the returned code just appears. It looks perfect... After I have done that, clicking on the button will again load the info from the database and it will show up; if I refresh the page, however, the returned stuff goes away again until I inspect the element.
Try it for yourself here. Click the orange button labeled "New Message."
NOTE:
The div that pops up is id navNew
The background transparent div that pops up is id navBackground
Within the div id navNew, I have a p id navNewBody that holds the information returned by the get PHP page below.
My code for the PHP getter page:
<?php
$link = mysql_connect('domain', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db(flf);
$r = mysql_query("SELECT * FROM new");
$first = mysql_num_rows($r);
$last = $first - 20;
echo '<p class="NavHead">New Sermons<br/><table width="90%" border="0" cellpadding="0" cellspacing="0">';
$ind = 0;
while($first > $last){
$me=mysql_fetch_array(mysql_query("SELECT * FROM new WHERE id='" . $first . "'"));
$name = $me["name"];
$row = 21-$ind;
echo '<tr id="row' . $row . '" class="navClosed" onclick="expand(' . "'" . 'row' . $row . "'" . ',' . $row . ')"><td colspan="4"> ' . $name . '</td></tr><tr id="row' . $row . 'e" style="visibility: hidden" class="navOpenClosed" onclick="dismiss(' . "'" . 'row' . $row . "'" . ')"></tr>';
$first = $first - 1;
$ind = $ind + 1;
}
echo "</table></p>";
?>
And here is the code I use to access the page (yes I imported jQuery):
function retNew(){
document.getElementById("navNewBody").innerHTML = '<span class="NavHead"><p align="center">Loading...Please Wait...<br/><br/><br/><img src="Sermons/Style/Loading.gif" /></p></span>';
document.getElementById("navNew").style.visibility = "visible";
$("#navNewBody").load("retNew.php");
}
What's wrong? It just doesn't make sense to me. I set the z-index to 10,000,000 and nothing happened. Any ideas? Thanks in advance.
I think you visibility is messing with the content. Try to use this load.
function retNew(){
$('#navNewBody').html('<div class="NavHead"><p align="center">Text</p></div>')
.load('retNew.php');
$('#navNew').fadeIn();
}
As of the close button, in your case it should be something like that:
<div id="navNew">
<a class="LargeNameU" onclick="offNavNew();return false;"
style='position:fixed; z-index: 1000; right:0px;top:0px'>
<img src="Sermons/Style/x.png" border='0'>
</a>
<p align="center" style="z-index:10000000" id="navNewBody">
and so on. Your .navNew already has a fixed position.
The visibility property has some very weird problems. I would recommend using display instead. The only difference between the two is that display removes the element entirely when it's set to none, while visibility just essentially makes the element invisible (but still leaves a space in the page where the element was).