i have this code :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
body {
background-image: url(../images/paper_03.png);
}
form {
background-image: url(../images/paper_02.png);
}
</style>
</head>
<?php
require("../function.php");
// echo sizeof($_SESSION['liste']);
?>
<body >
<form name="log" method="post" style="position: absolute; top:50px; left: 320px; width: 600px; height: 100%;" >
<table BORDER=2 style="position: relative; top:15px; left: 3px;" >
<TR>
<TH style="width:100px"><font color="blue">Date</font></TH>
<TH style="width:400px"><font color="blue">Location</font></TH>
<TH style="width:400px"><font color="blue">Job Title</font></TH>
<TH style="width:300px"><font color="blue">Company</font></TH>
</TR>
<?php
session_start();
for($i=0;$i<sizeof($_SESSION['liste']);$i++){
?>
<TR>
<td ><center><label><?php echo $_SESSION['liste'][$i]['date']; ?></label></center></td>
<td ><label><?php echo $_SESSION['liste'][$i]['region'].','.$_SESSION['liste'][$i]['city'].','.$_SESSION['liste'][$i]['state']; ?></label></td>
<td ><center><label><?php echo $_SESSION['liste'][$i]['title']; ?></label></center></td>
<td ><center><label><?php echo $_SESSION['liste'][$i]['comapany_name']; ?></label></center></td>
</TR>
<?php
}
?>
</table>
</form>
</body>
</html>
i have a form i want that every 10 results be displayed togother ie add the pagination to my form with two icons ( next, previous ).
can i do this only with php?
do i need ajax in this work?
Pass a $liststart value in as a parameter to your code (get it with $liststart = $_REQUEST['liststart']).
Then adjust your loop to loop from $liststart to $liststart+10.
Make a button that onClick, goes to your code above with the new $liststart value. for example for the 'next' button on the first page, use echo "' onClick='location.href=\"yourcodeabove.php?liststart=".$liststart+10."\";'>";
or if you prefer, you could do it without javascript by making the next and prev buttons their own forms. like this:
<FORM METHOD="LINK" ACTION="yourcodeabove.php?liststart="<?php $liststart+10 ?>">
<INPUT TYPE="submit" VALUE="next->">
</FORM>
close out your other form first (which doesn't look like it needs to be a form actually... could be a div just as well). forms usually have 'actions' and are submitted with buttons but since you'll have 2 buttons (next and prev) each could be their own form with either the javascript onClick or the form method.
If you use mysql this should work:
$page = $_GET['page'];
$query = mysql_query("SELECT * FROM some_table LIMIT $page, 10");
And do some work with $query variable, your links should be something like this:
Next
Related
Following is the table i created for displaying the Restaurant Name, Location and Menu for table owners.
Now each of the row for the column Menu have Button as values.
My table is ready with perfect values.
NOW MY PROBLEM IS HOW TO DO:-
Upon clicking the button corresponding to the each Restaurant, a new File(openmenu.php) will open and will echo the Restaurant Name, Mobile Number of that Restaurant and the menu.
But so far, on clicking every Button ,I can only display above entries of the Last row of the table. Help Me Out. I am new to php.
table.php
<?php
include 'nav.php';
$sql = 'SELECT * FROM owners';
$query = mysqli_query($con, $sql);
if (!$query) {
die ('SQL Error: ' . mysqli_error($con));
}
?>
<html>
<head>
<link rel = "stylesheet" type = "text/css" href = "css/style.css">
<style>
.data-table{
width: 1024px;
margin-left: 150px;
text-align:center;
border: 1px solid firebrick;
background-color: white;
}
td,th{
border: 1px solid firebrick; padding: 3px 2px 1px 1px;
}
</style>
</head>
<body>
<div class="container">
<article>
<table class="data-table">
<thead>
<tr>
<th>Restuarant Name</th>
<th>Location</th>
<th>Menu</th>
</tr>
<tr>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_array($query)){
$_SESSION['resphone'] = $row['resphone'];
$_SESSION['restaur'] = $row['restaur'];
echo '<tr>
<td>'.$row['restaur'].'</td>
<td>'.$row['loc'].'</td>
<td style="background-color:firebrick;"><form method="post" action="openmenu.php?id=$row[restaur]"><input value="<?php echo $restaur;?>" type="hidden">
<input type="submit" value="View"></form></td>
</tr>';
}
?>
</tbody>
</table>
</form>
</article>
</div>
</body>
</html>
openmenu.php
<?php
include('nav.php');
?>
<html>
<head>
<link rel="stylesheet" href="css/style.css">
<style>
table, td {
border: none;
text-align: center;
text-align-last: center;
}
</style>
</head>
<body>
<div class="container">
<article>
<form method="get" align="center" action="" class="formwrap" enctype='multipart/form-data'>
<h1><?php $restaur = $_SESSION['restaur'];
echo $restaur ;?></h1>
<h1>Call to Order:</h1>
<?php $resphone = $_SESSION['resphone'];
echo $resphone;
?>
<br>
<br>
<?php
$sql = "select img from owners where restaur ='$restaur'";
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_array($result);
$image_src2 = "upload/".$row['img'];
?>
<img src='<?php echo $image_src2; ?>' >
</form>
</article>
</div>
</body>
</html>
Issue 1
In this snippet you are setting the session variables resphone and restaur to the values of the store you are currently iterating over. Over and over again. That's why you're only ever getting the last store's information - it's the last things you set those variables to.
while ($row = mysqli_fetch_array($query)){
$_SESSION['resphone'] = $row['resphone'];
$_SESSION['restaur'] = $row['restaur'];
Issue 2
You should probably change the form method to get and discard the unused hidden input like so:
<form method="post" action="openmenu.php?id=<?=$row['restaur']?>">
<input type="submit" value="View">
</form>
Or more likely just change it a plain old a link:
View
Issue 3
You're completely ignoring store id requested in openmenu.php. You are using $_SESSION where you should be using $_REQUEST or $_GET. I'm not going to give an example of how you should do that. Instead, please refer to this answer before moving any further.
first you getting data from database & then use view button for openmenu.php but why u use this way
<form method="post" action="openmenu.php?id=$row[restaur]"><input value="<?php echo $restaur;?>" type="hidden"><input type="submit" value="View"></form>
I am echoing records from the database which are wrapped with html tags and was trying to put some effect on the echoed data. When I click the edit link, the textfield should shake. It works on the first element but when I click the edit link of the next element, the first textfield still shakes and not the other one.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Wallpost</title>
<style>
.wallpost input[type="text"]{
width: 500px;
height: 20px;
}
.wallpost input[type="submit"]{
height: 26px;
}
.user{
font-weight: bold;
font-size: 20px;
}
.post{
font-family: Arial;
}
a{
text-decoration: none;
}
</style>
</head>
<body>
<?php
require_once 'dbconfig.php';
$user = $_SESSION['user'];;
echo '<form action="post.php" method="post" class="wallpost"><input
type="text" name="post" size="50"><input type="submit" name="wallpost"
value="Post"></form>';
$query = $con->query("SELECT * FROM statuspost ORDER BY id DESC");
while($i = $query->fetch_object()){
//echo $i->post.' '.$i->id.' <a href="wallpost.php?type=post&
id='.$i->id.'" >Remove</a>'.'<br/>';
echo '<span class="user">'.$i->user.'</span>'.'<br>'.'<span
class="post">'.$i->post.'</span>'.' <form action="editpost.php?type=post&
id='.$i->id.'" method="post"><span id="edit"><input type="text"
name="edit">
<br/><input type="submit" value="Edit"></span><a href="#"
onclick="showEdit();">Edit </a><a href="remove.php?type=post&
id='.$i->id.'" >Remove</a></form> '.'<br/><br/>';
//echo '<div id="post">'.$i->post.' '.$i->id.'<a href="#"
id="anchor" class="',$i->id,'" onclick="del();">Remove</a></div>
<br/>';
}
?>
<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.2.0
/prototype.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0
/scriptaculous.js"></script>
<script>
function showEdit(){
Effect.Shake('edit');
}
</script>
</body>
</html>
Replace <span id="edit"> by something like <span id="edit'.$i->id.'"> to have different ids on each elements. Then of course, showEdit() must know which id it has to shake, so it has to take a parameter. Or even simpler: replace onclick="showEdit();" by onclick="Effect.Shake(\'edit'.$i->id.'\');"
Scriptaculous effects take either an ID or a JavaScript reference to a DOM element as their first argument, so if you add a classname to your multiple elements, you can shake all of them at once like this:
<span class="shake-me">...</span>
<span class="shake-me">...</span>
<span class="shake-me">...</span>
Inside an enumerator:
$$('.shake-me').each(function(elm){
Effect.Shake(elm);
});
I've below PHP code which shows QR code & I'm showing it in center on submitting password. Now, since I'm keeping it in center, the rest of the page appears white & I want entire browser background color to be in blue. I tried putting bgcolor but that only changes the middle section's background where image appears & I need entire browser's background color to be blue
Here is my code for reference:
<!DOCTYPE HTML>
<html>
<head>
<style>
.error {color: #FF0000;}
html, body {
height: 100%;
}
html {
display: table;
margin: auto;
}
body {
vertical-align: middle;
}
</style>
</head>
<body>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// reading from post
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<table width="380px">
<tr>
<td valign="top">Password:</td>
<td><input type="text" name="password" value="<?php echo $password; ?>"><span class="error">* <?php echo $passwordErr;?></span></td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" name="submit" value="Submit">
</td>
</tr>
</table>
</form>
<?php
if ($password) {
echo "<img src='./myqrcode.php?password=$password' />";
?>
</body>
</html>
Can any one tell me how to put blue color as background?
Thanks
Do you want the background in the body? Can you show us a screenshot?
You can try
body {
vertical-align: middle;
background-color: blue;
}
By the way, it's a bad idea to use tables for designing the layout of the page. Use divs instead. Like here:
http://www.w3schools.com/html/html_layout.asp
And also don't use old-fashioned html tags like "bgcolor", use only CSS for styling.
<body style="backgroundoclor:blue;">
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// reading from post
}
?>
I'm using CentOS 6.4 with apache installed. I have a single php file called cmsSearch.php. At the top of the file I have PHP that executes fine (queries a Sphinx Search index). But, any php I try to run in the HTML that is below (trying to run a foreach and populate a table with the results of the Sphinx Search) just gets commented out when I view the page in the console (Chrome). Here is the whole cmsSearch.php file:
<?php
require("sphinxapi.php");
if($_POST['keyword'])
{
$keyword = $_POST['keyword'];
$client = new SphinxClient();
$client->SetMatchMode(SPH_MATCH_ANY);
$result = $client->Query($keyword, "staffDirectoryMember");
if(!$result)
{
print "ERROR: " . $client->GetLastError();
}
else
{
var_dump($result["matches"]);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Sphinx Test</title>
<style>
.container
{
border: solid 1px black;
height: 350px;
width: 700px;
margin: auto;
padding: 5px;
}
.output
{
margin-top:20px;
border: solid 1px red;
height: 200px;
}
</style>
</head>
<body>
<?echo "TEST"; ?>
<div class="container">
<div>
<form method="post" action="cmsSearch.php">
<input type="text" name="keyword">
<input type="submit" value="Search">
</form>
<div class="output">
<? echo "test2"; ?>
<table>
<thead>
<tr>
<th>ID</th>
<th>Weight</th>
<th>ClientId</th>
<th>DomainId</th>
<th>ContentTypeId</th>
</tr>
</thead>
<tbody>
<?
echo "Above for loop";
foreach($result["matches"] as $match)
{
echo "Print from for loop:";
var_dump($match);
?>
<!-- <tr>
<td><?=$match[id]?></td>
<td><?=$match[weight]?></td>
<td><?=$match[attrs][clientid]?></td>
<td><?=$match[attrs][domainid]?></td>
<td><?=$match[attrs][contenttypeid]?></td>
</tr> -->
<?}
echo "After for loop";
?>
</tbody>
</table>
</div>
</div>
</div>
Not sure why the php executes at the top fine (i can echo out and the var dump works), but then any php put in the HTML just shows as comments and doesn't do anything. Anyone have an idea?
Your PHP contained inside the HTML is using short tags which can be turned off in your php.ini file. Take a look at this directive and make sure it is set to true if you want to use them:
short_open_tag true
http://www.php.net/manual/en/ini.core.php#ini.short-open-tag
Try using <?php to start your PHP blocks, not <?... It's the difference between the blocks of code.
i have this code:
<?php
$i=5;
while($i > 0){
echo '
<table width="500px" border="1">
<tr>
<td>
<button id="button">Show comments</button>
</td>
</tr>
<tr>
<td id="comments" style="display:none;height:300px;width:100%;"></td>
</tr>
</table>
<script type="text/javascript">
$("#button").toggle(
function (){
$("#button").text("Hide Comments");
document.getElementById("comments").style.display="inline";
},function (){
$("#button").text("Show Comments");
document.getElementById("comments").style.display="none";
}
);
</script>
<script type="text/javascript" src="jquery.js"></script>
';
$i--;
}
?>
When the show comments button is clicked the comment box should show up. It works for the first one. But it doesn't work for the others.What's wrong?
I'd just escape the php interpreter and print the HTML markup directly into the page. I'd also change the ids to classes, so we can more easily reuse them without quirky additional numbers.
<?php
$i=5;
while($i > 0):
?>
<table width="500px" border="1">
<tr>
<td><button class="button" data-clicked="0">Show comments</button></td>
</tr>
<tr>
<td class="comments" style="display:none;height:300px;width:100%;"></td>
</tr>
</table>
<?php
$i--;
endwhile;
?>
I don't know what the element with an ID of show is, but we'll just assume it was the button.
$(".button").click(function (){
var $this = $(this);
if(!$this.data('clicked')){
$this.text("Hide Comments");
$this.closest('table').find('.comments').css('display', 'inline');
$this.data('clicked', 1);
}else{
$this.text("Show Comments");
$this.closest('table').find('.comments').css('display', 'none');
$this.data('clicked', 0);
}
});
Don't print that javascript in a while loop in php, just include it in the head of the page, or in a separate file.
Edit
As indicated in a comment below,in jQuery 1.9 the toggle no longer works as you're intending to use it, as a work around, you can add a data attribute to the button, and check it each time we click.
<button class="button" data-clicked="0">
As you can see we've added the new data-clicked attribute.
In our JavaScript above, you can see that we've completely changed how it works. We perform our own if/else to check the data-clicked state.
It is generally good practice to separate code, markup and style declarations. As a matter of style, I prefer numbered IDs. I find they help with debugging. ymmv
I also like to animate changes so people can more easily follow a change.
<!doctype html>
<html>
<head>
<title>Button Testing 1 2 3</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<style>
.comment {
display: none;
height: 0px;
width: 500px;
}
td {
width: 500px;
border: 1px solid #555;
border-collapse: collapse;
}
</style>
</head>
<body>
<?
$j = 0;
while ($j < 5 ) {
?>
<table>
<tr>
<td>
<button id="button_<?= $j ?>" class="button">Show comments</button>
</td>
</tr>
<tr>
<td class="comment"><span id="comment_<?= $j ?>">J = <?= $j ?></span></td>
</tr>
</table>
<?
$j++;
} ?>
<script type="text/javascript">
$(document).ready(function(){
$(".button").click(function(){
var id = $(this).attr('id');
var j = id.substr(id.indexOf('_') +1);
if ($(this).hasClass('revealed')) {
$(this).removeClass('revealed').text('Show Comments');
$('#comment_'+j).removeClass('revealed').parent().animate({'height' : 0}, function(){$(this).css({'display': 'none'})});
} else {
$(this).addClass('revealed').text('Hide Comments');
$('#comment_'+j).addClass('revealed').parent().css({'display': 'inline'}).animate({'height' : '300px'});
}
});
});
</script>
</body>
</html>