Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Why does this not work? I want to be redirected to id?1 and remove.php removes it from table. How is this done?
// Get all the data from the "example" table
$result = mysql_query("SELECT * FROM pages")
or die(mysql_error());
echo "<table border='1'>";
while ($row = mysql_fetch_array($result)) {
echo "<li class='list-group-item'>";
echo $row['header'];
echo "<br/>";
echo $row['description'];
echo "<br/>";
echo "<button type='button' class='btn btn-default btn-xs' style='margin-top:8px;margin-bottom:0px;'>Ändra innehåll</button>";
echo " ";
echo "<form method='POST'><a href='delete.php?". $row['page_id']."' name='action' class='btn btn-danger btn-xs' style='margin-top:8px;margin-bottom:0px;'>Ta bort sida</a></form>";
echo "<td><a href='obrisi.php?id=$id'>Delete</a></td>";
echo "</li>";
}
echo "</table>";
?>
delete.php
<?php
if (isset($_POST['1']))
{
foreach ($_POST['id'] as $page_id)
{
if (!mysql_query("DELETE FROM pages WHERE id = '$page_id'"))
{
echo mysql_error();
}
}
}
?>
Please help me. Thanks in advance.
You can not get the id in POST becuase you are using it as a Query String. You can get it as:
$page_id = intval( $_GET['id'] );
Now you can check it as:
if( $page_id > 0 ){
// your stuff.. use this id in your query
}
What I have changed:
Use $_GET (SUPER GLOBAL) instead of $_POST becuase of query string.
Side Note:
There is no need to use foreach loop becuase it's not an array.
I suggest you to use mysqli_* or PDO instead of mysql_* becuase its deprecated and not available in PHP 7.
Form - PHP Manual
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
here is my code, it takes informations from database, but how can i stop TH from repeating in every row pls help :
echo '<table border="0">'."\n";
$result = mysql_query("select projektet.p_id, projektet.p_emri, arqitekti.a_emri, arqitekti.a_mbiemri, llojet.ll_emri, projektet.p_marrjes, projektet.p_dorrezimit, projektet.p_cmimi from projektet,arqitekti,llojet where projektet.a_id = arqitekti.a_id and projektet.ll_id = llojet.ll_id order by p_id desc");
while ($row = mysql_fetch_row($result) ) {
echo "<TR><TH>ID<TH>Emri Projektit<TH>Emri Arqitektit<TH>Mbiemri<TH>Lloji projektit<TH>Data Marrjes<TH>Data Dorrezimit<TH>Cmimi<TH>Opcionet";
echo "<tr><td>";
echo("$row[0]");
echo("</td><td>");
echo("$row[1]");
echo("</td><td>");
echo("$row[2]");
echo("</td><td>");
echo("$row[3]");
echo("</td><td>");
echo("$row[4]");
echo("</td><td>");
echo("$row[5]");
echo("</td><td>");
echo("$row[6]");
echo("</td><td>");
echo("$row[7]");
echo("</td><td>");
echo('<a href=projekt_edit.php?id='.($row[0]).'><img src="images/modifiko.png" /></a> ');
echo('<a href=projekt_fshi.php?id='.($row[0]).'><img src="images/fshi.png" /></a> ');
echo("</tr>\n");
and here is how it looks .. well its repeating TH and i dont want it :
http://i.imgur.com/gKqYIuy.png
Write this statement before While loop
echo "<TR><TH>ID<TH>Emri Projektit<TH>Emri Arqitektit<TH>Mbiemri<TH>Lloji projektit<TH>Data Marrjes<TH>Data Dorrezimit<TH>Cmimi<TH>Opcionet";
while ($row = mysql_fetch_row($result) ) {
...
}
Write header before while loop.
echo "<TR><TH>ID<TH>Emri Projektit<TH>Emri Arqitektit<TH>Mbiemri<TH>Lloji projektit<TH>Data Marrjes<TH>Data Dorrezimit<TH>Cmimi<TH>Opcionet";
while ($row = mysql_fetch_row($result) ) {
// other stuff;
}
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 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 9 years ago.
Improve this question
I am trying to output a list of links based upon database query result. The query works fine but I need to get the information for the links to populated by the same results. In this example I need to create the following string to pass along to my loadXMLDoc() Function..
$ridesid
$catrating
This is the actual line of code that is giving me an issue:
echo "<a href='#' onmousedown='url1 ='attraction_page.php?rideid=$ridesid&catrating=$catrating onclick ='loadXMLDoc()'>$rides</a>";
I am pretty sure it is just an issue with the quotes but I have been searching and searching for a solution or an example of how to properly code this line but can't find anything. Can anyone help?
Thanks
Here is the complete PHP block:
<?php
$sql3 = "SELECT `Record_ID`, `Name` FROM `rides` WHERE `Rating` = $catrating ORDER BY `Name`";
$result3=mysql_query($sql3)or die(mysql_error());
//var_dump ($result3);
$num = mysql_num_rows($result3);
//WHILE ($row3 = mysql_fetch_array($result3)){
echo "<table>";
// Ride Category Heading
if ($catrating == 1)
echo "<span class='headertext'>Kiddie Rides</span><br \>";
if ($catrating == 2)
echo "<span class='headertext'>Family Rides</span><br \>";
if ($catrating == 3)
echo "<span class='headertext'>Thrill Rides</span><br \>";
// end heading
for ($i = 0; $i < $num; $i++){
$row3 = mysql_fetch_array($result3);
//var_dump($row3);
$ridesid = $row3[0];
$rides = $row3[1];
//echo "<a href='attraction_page.php?rideID=". urlencode($ridesid) ."&catrating=". urlencode($catrating) ."'>$rides</a>";
echo "<tr>";
//echo "<a href='#' onmousedown='url1 ='attraction_page.php?rideID=$ridesid&catrating=$catrating' onclick='loadXMLDoc()'>$rides</a>";
//echo "<a href='#' onmousedown='url1 ='attraction_page.php?rideID=30&catrating=1 onclick='loadXMLDoc()'>$rides</a>";
//echo "<a href='attraction_page.php?rideID=". urlencode($ridesid) ."&catrating=". urlencode($catrating) ."'>$rides</a>";
echo "<a href='#' onmousedown='url1 ='attraction_page.php?rideid=$ridesid&catrating=$catrating onclick ='loadXMLDoc()'>$rides</a>";
echo "<br />";
echo "</tr>";
}
echo '</table>';
// }
?>
You must escape your quotes.
echo "<a href='javascript:void(0);' onmousedown='url1 =\'attraction_page.php?rideid=$ridesid&catrating=$catrating\';' onclick ='loadXMLDoc()'>$rides</a>";
I would also replace the # in your href attribute with javascript:void(0)
I would recommend to leave quotes when you want to use a var, or use the {$var} syntax
echo "<a href='#' onmousedown='url1 =\'attraction_page.php?rideid=".$ridesid."&catrating=".$catrating."\'' onclick ='loadXMLDoc()'>".$rides."</a>";
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a simple code which gives me error. Could someone help me to explain what would be the best solution. I am not just interested the solution rather than the explanation as I have been struggling with this type of listing. I have googled it but I could not find a dummy explanation.
Many thanks
<?php
// Run a Query
$result = mysql_query("SELECT * FROM weblinks ORDER BY yeargroup ASC");
$a=-1;
while ($row = mysql_fetch_array($result)) {
if ($row['yeargroup'] == $a) {
echo "<h2 class=\"class\">Year ".$row['yeargroup']."</h2>";
} else {
echo "<ul><li>";
echo "<img src=\"" . $row['img'] . "\"/>";
echo "".$row['webname']." - ".$row['weblink'];
echo "<div class=\"text\">".$row['content']."</div>";
echo "</li></ul>";
}
$a=$row['yeargroup'];
}
?>
fixed the typo error, thanks
This is how it should be
Year 1
Link1
Link2
Link3
Year 2
Link1
Link2
Link3
etc.
$a = null;
while ($row = mysql_fetch_array($result)) {
//check if $a is equal to the current yeargroup
//if not, output the header and open the list
if ($row['yeargroup'] <> $a) {
echo "<h2 class=\"class\">Year ".$row['yeargroup']."</h2>";
echo "<ul>";
}
echo "<li>";
echo "<img src=\"" . $row['img'] . "\"/>";
echo "".$row['webname']." - ".$row['weblink'];
echo "<div class=\"text\">".$row['content']."</div>";
echo "</li>";
//check if $a is equal to the current yeargroup
//if not, close the list and set $a to the yeargroup for the loop
if ($row['yeargroup'] <> $a) {
echo "</ul>";
$a = $row['yeargroup'];
}
}
Here is my piece of code:
$a=mysql_query("SELECT denumire_intrebare,denumire_varianta,tip_intrebare
FROM intrebari,variante
WHERE intrebari.cod_chestionar='".$_SESSION['cod']."'
AND intrebari.cod_intrebare=variante.cod_intrebare");
while($b=mysql_fetch_array($a))
if($b['tip_intrebare']==3)
{
echo $b['denumire_intrebare'];
echo "<br>";
echo "<input type='checkbox' name='option1' value='Milk'>";
echo $b['denumire_varianta'];
echo "<br>";
}
So let me explain. I query the database and it brings me up a question and the answers that are related to it. I want the answers to put them as checkbox answers. The problem is that my question is repeating for all the answers. So if i have 5 answers then the question appears 5 times like this: question answer1, question answer2, ... . I want my question to appear only once with the answers under the question. I'm missing something but I don't know what. Any help?
Make an array with all $b['denumire_varianta'] and use a foreach() after the while has finished, also make your checkboxes array so you can get them afterwards:
$variante = array();
while($b=mysql_fetch_array($a)) {
if($b['tip_intrebare']==3){
$intrebare = $b['denumire_intrebare'];
$variante[] = $b['denumire_varianta'];
}
}
echo $intrebare."<br />";
foreach($variante as $varianta){
echo "<input type='checkbox' name='option[]' value='".$varianta."'>";
echo $varianta."<br />";
}