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.
Related
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
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
What´s wrong with the following code?
$cores = array ("#FF0000","#FFBF00","#FFFF00","#04B404","#58FAF4","#0101DF");
foreach ($cores as $cor)
{
echo "<tr>";
echo "<td bgcolor = $cor></td>";
echo "</tr>";
}
But this code works:
$cores = array ("#FF0000","#FFBF00","#FFFF00","#04B404","#58FAF4","#0101DF");
for ($i=0; $i<7; $i++)
{
echo "<tr>";
echo "<td bgcolor=$cores[$i]></td>";
echo "</tr>";
}
Besides, it is not giving the colors in columns (which is the goal), but in rows.
You are missing quotes around the variable:
foreach ($cores as $cor)
{
echo "<tr>";
echo "<td bgcolor = '$cor'></td>";
echo "</tr>";
}
Do this:
$colors = array("#FF0000","#FFBF00","#FFFF00","#04B404","#58FAF4","#0101DF");
$color = $colors[array_rand($colors)];
and pass $color variable to bgcolor in td
echo "<tr>";
echo "<td bgcolor = '$color'></td>";
echo "</tr>";
and it will pick up colors randomly.
If your goal is the column, use:
<?php
$cores = array ("#FF0000","#FFBF00","#FFFF00","#04B404","#58FAF4","#0101DF");
echo "<table>";
echo "<tr>";
foreach ($cores as $cor)
{
echo "<td bgcolor= \"$cor\">1</td>";
}
echo "</tr>";
echo "</table>";
?>
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 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 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.