I am trying to scale my table in PHP for a mobile web app, and i have quite a lot of fields echoed out.
Is there a neat way to style these as they are too far right at the minute
echo "<table cellspacing=\"0\" class=\"recordsTableBG\"> <thead class=\"recordsTableHeader\" >";
echo '<tr class="alternateRowColor">';
echo '<tr><th>id</th><th>amount</th><th>submission</th><th>project_id</th><th>status</th><th>description</th><th>delete</th></tr></thead>';
//echo "<form method='post' action=\"pmsystem.php?page=sentbox\">".
echo "<form method='post' action=\"viewrecordsemp1.php\">".
" <input type=\"hidden\" name=\"deleteMessage\" value=\"yes\">".
" <input type=\"hidden\" name=\"id\" value=\"$id\">".
"<td><b>$id </b> <br></td>".
"<td>$amount</a><br/></td>".
"<td>$submission</a><br/></td>".
"<td>$project_id</a><br/></td>".
"<td>$status</a><br/></td>".
"<td>$description</a><br/></td>".
" <input type=\"hidden\" name=\"thisPage\" value=\"$thisPage\">".
" <td> <input type=\"image\" src=\"images/delete.jpg\" alt=\"Delete contact\" onClick = \"return confirm('$first_name are you sure you want to delete this message?')\";></td>".
" </form>";
echo "</table>";
echo "<hr = '1'>";
I'm not exactly sure what data is in these fields, but you could echo maybe the 3 most essential columns and have the rest of the data put into an invisible <div> that takes up the screen. The <div> is unhidden when the entry is clicked and all the options are neatly displayed. This would mean you would have to have a separate set of PHP code to run on mobile, you have to keep the table format pretty much the same if you want to just do a mobile stylesheet.
But keep in mind that many mobile phone users use the phone horizontally to browse the web on non-mobile-specific sites. Unless your site is specifically designed for mobile or the text still goes offscreen in horizontal view, consider leaving it the way it is unless people are complaining.
Related
The following code segment is used by me to load the contents in the database as a table!(each row has a button with value load!
while($row=mysqli_fetch_array($result))
{
echo"
<tr id='rowNum'>
<td >".$row['No.']."</td>
<td >".$row['NIC']."</td>
<td >".$row['DP']."</td>
<td >".$row['DPTime']."</td>
<td >".$row['Telephone']."</td>
<td> <input type='button' id='load' class='btn btn-success' value='Load number' disabled=' '></td>
</tr>";
}
I also have the following text box on the same web page(outside the above table)!
echo "<input type=text name="display number">"
when i press the load button of the the relevant row of the table i want to display the No. of that row in the text box! how can i achieve this?
There are several problems with the code you posted. I'll do my best to get you on your way... You will want to do what you have described with JavaScript which runs on the client. Many people use libraries these days to work with JavaScript but to avoid added confusion I will recommend looking into jQuery and write my solution in the native code.
while($row=mysqli_fetch_array($result)) {
echo("
<tr id='rowNum".$row['No.']."'>
<td>".$row['No.']."</td>
<td>".$row['NIC']."</td>
<td>".$row['DP']."</td>
<td>".$row['DPTime']."</td>
<td>".$row['Telephone']."</td>
<td>
<input type='button' id='load".$row['No.']."' onClick='javascript:document.getElementById(\"displayNumber\").value=this.parentNode.parentNode.firstChild.innerHTML;' class='btn btn-success' value='Load Number'>
</td>
</tr>"
);
}
One big talking point is that you need to make sure that if you assign an id to any HTML element, unless it is a collection then that ID must be unique, otherwise your HTML will be just as invalid as your id. Also: Don't use spaces in names or ids. Just don't.
Finally, to fix up the input which is outside the table where you want the number to dynamically appear:
echo("<input type='text' name='displayNumber' id='displayNumber'>");
I have a PHP code which generates a dynamic list inside a form like the following, note that the list is built dynamically from database:
echo '<form name="List" action="checkList.php" method="post">';
while($rows=mysqli_fetch_array($sql))
{
echo "<input type='password' name='code' id='code'>";
echo "<input type='hidden' name='SessionID' id='SessionID' value='$rows[0]' />";
echo "<input type='submit' value='Take Survey'>";
}
What I need is to POST the data corresponding to the user choice when he clicks on the button for that row to another page.
If we use hyperlinks with query strings there will be no problem as I'll receive the data from the other page using a GET request and the hyperlinks would be static when showed to the user.
Also I need to obtain the user input from a textbox which is only possible with POST request.
Simply from the other page (checkList.php) I need these data for further processing:
$SessionID=$_POST['SessionID'];
$Code=$_POST['code'];
As I have a while loop that generates the fields, I always receive the last entry form the database and not the one corresponding to the line (row) that the user chosed from the LIST.
I'm going to recommend that you clean up the names of variables so that your code can
at least tell us what it's supposed to do. It should be rare that someone looks at your code
and has a lot of trouble trying to see what you're trying to accomplish :P, ESPECIALLY when you need help with something ;]. I'm going to try some things and hope that it makes doing what you want easier to comprehend and perhaps get you your answer.
It's good to try your best to not echo large amounts of HTML unnecessarily within a script , so firstly I'm going to remove the
echos from where they are not necessary.
Secondly, I'm going to use a mysql function that returns an easier to process result.
$user = mysqli_fetch_assoc($sql)
Third, I don't know if form having a name actually does anything for the backend or frontend of php, so I'm
just going to remove some of the extra crust that you have floating around that is either invalid HTML
or just doesn't add any value to what you're trying to do as you've presented it to us.
And yes, we "note" that you're building something from the database because the code looks like it does =P.
I'm also sooo sad seeing no recommendations from the other answers in regard to coding style or anything in regard to echoing html like this :(.
<?php while($user = mysqli_fetch_assoc($sql)): ?>
<form action="checkList.php" method="post">
<input type='password' name='code' value='<?php echo $user['code'] ?>' />
<input type='hidden' name='SessionID' value='<?php echo $user['id'] //Whatever you named the field that goes here ?>' />
<input type='submit' value='Take Survey' />
</form>
<?php endwhile; ?>
i not sure this is correct
echo '<form name="List" method="post">';
while($rows=mysqli_fetch_array($result))
{
echo "<input type='password' name='code' id='code'>";
echo "<input type='button' value='Take Survey' onclick=show($rows[0])>";
echo "<br>";
}
and javascript
<script>
function show(id)
{
alert(id);
window.location="checkList.php?id="+id;
}
</script>
On checkList.php
$id=$_GET['id'];
echo $id;
You can just check in checkList.php whether $_POST['code'] exists and if exists retrieve $_POST['SessionID'] which will be generated from database. But one thing, if You have all hidden fields in one form, they all will be sent, so You need to think how to correct that - maybe seperate forms for each hidden field, submit button and maybe other POST fields.
And afterwards, You will be able to get data in the way You need - $SessionID=$_POST['SessionID'];
I suppose it is the easiest way to solve that.
You can try something like this:
while($rows=mysqli_fetch_array($sql))
{
$index = 1;
echo "<input type='password' name='code' id='code'>";
//Attach $index with SessionID
echo "<input type='hidden' name='SessionID_$index' id='SessionID' value='$rows[0]' />";
echo "<input type='submit' value='Take Survey'>";
}
On checkList.php
<?php
$num = explode('_', $_POST['SessionID']);
$num = $num[1];
//in $num you will get the number of row where you can perform action
?>
$form = 1;
while($rows=mysqli_fetch_array($sql))
{
echo '<form name="List_$form" action="checkList.php" method="post">';
echo "<input type='password' name='code' id='code_$form'>";
echo "<input type='hidden' name='SessionID' id='SessionID_$form' value='$rows[0]' />";
echo "<input type='submit' value='Take Survey'>";
echo '</form>';
$form++;
}
I am making a table for booking time, I have put times as checkboxs, checboxs are all from one form, and I wand that user can select one checkbox and after submit the form, checkbox becomes unselectable or disappears from. I tried to validate if data is found on database and then make it disappear or unselecteble, but it was not successful.
my table looks like this:
http://i.imgur.com/hQdbl.jpg?1
Actually date and time come from another table on database. This is my php code for each check bos:
echo"
<input type='radio' name='datetime' value='". $row['day1']." ".$row['time1']."'>
<p>". $row['day1'] ,"</p><br/>". $row['time1'] ."
can you please help me :-\
If I got your question right you meant something like this?
if($_POST['datetime'] != ($row['day1'] . " " . $row['time1'])) {
echo"
<input type='radio' name='datetime' value='". $row['day1']." ".$row['time1']."' disabled>
<p>". $row['day1'] ,"</p><br/>". $row['time1'] ."
// etc
} else {
echo"
<input type='radio' name='datetime' value='". $row['day1']." ".$row['time1']."'>
<p>". $row['day1'] ,"</p><br/>". $row['time1'] ."
}
I'm trying to use AJAX to make my website a little slicker than it currently is.
I have a block of code that shows the following
if($guess == 0){
echo "Enter a guess:;
*AJAX form* ---> inserts a MySQL database record with the users guess
<div to show results of script for form> - not necessarily needed
}else{
echo "Update your guess:";
*SAME AJAX form* ---> updates the MySQL database record with the users new guess
<div to show results of script for form> - - not necessarily needed
}
The problem I'm having is that I want part of the webpage to show:
Your latest guess is: £x.xx
However because a user will start off with 0 guesses, and AJAX sends the form "behind" the scenes, I'm struggling in knowing how to show the above line once the user has made a guess.
So also that way when they revisit the page at a later date, it shows the last guess they had.
Those are the only 2 elements of the page I want to be able to refresh, the rest of the information doesn't have to refresh.
Some more code here:
<?php
if($guessess_open == 1){
echo "<h2>guesses are CLOSED</h2>";
}
else{
//it's this part that I want to have always shown on the page, but when I visit the page fresh it doesn't show me any results.
<div id="results"></div>
<form name="myform" id="myform" action="" method="POST">
<!-- The all important guess field -->
<label for="guess" id="guess_label">Guess<br></label>
<input type="text" name="guess" id="guess" size="10" value=""/>
<?php
echo "<input type='hidden' name='user_id' id='user_id' size='10' value='$user'/>";
echo "<input type='hidden' name='item_id' id='item_id' size='10' value='$itemID'/>";
echo "<input type='hidden' name='title' id='title' size='100' value='$title2'/>";
echo "<input type='hidden' name='owner_id' id='owner_id' size='10' value='$ownerid'/>";
echo "<input type='hidden' name='guesses_open' id='guesses_open' size='10' value='$guesses_open'/>";
echo "<input type='hidden' name='exist' id='exist' size='10' value='$exist'/>";
?>
<!-- The Submit button -->
<br>
<input type="image" name="submit" src="URL" width="150px" height="100px">
</form>
The only way I can get it to show something in that part of the page is to have some code in which checks a database for a guess and if it exists display the result, but then when I submit a new form, because it only updates the results it doesn't update the part of code for example could include
else{
include("URL.php?item_id=" . $itemID. "&user=" .$user. "");?>
//it's this part that I want to have always shown on the page, but when I visit the page fresh it doesn't show me any results.
<div id="results"></div>
which shows the latest guess when a user visits the page, but then when a new guess is made, this doesn't update... I don't have to have my forms php up display the result if the above part of code would update each time I make a guess... I hope this is clearer?
the below code works perfectly in FF and CHROME but not in IE. Please help. I have commented out my santize functions as i thought they might be affecting it, but it still does the same.... nothing in IE.
Thank you in advance for any assistance.
<?php
//IF UPDATE BUCKET CHANGE STATUS...
if(isset($_POST['updatebucket'])){
$complete = $_POST["complete"];
$bucketid = $_POST["bucketid"];
//$complete = sanitizeone($_POST["complete"], "plain");
//$complete = strip_word_html($complete);
//$bucketid = sanitizeone($_POST["bucketid"], "plain");
//$bucketid = strip_word_html($bucketid);
if ($complete=="1")
$complete = "0";
else
$complete = "1";
$updatebucket = "UPDATE membersbuckets SET complete = '$complete' WHERE userid = '$userid' AND bucketid = '$bucketid'";
mysql_query($updatebucket);
}
?>
and the front end....
<? if ($complete=="1") {
echo "<form action='' method='post' name='updatebucket'><input name='complete' type='hidden' value=" .$complete. " /><input name='userid' type='hidden' value=" .$userid. " /><input name='bucketid' type='hidden' value=" .$bucketid. " /><input type='image' name='updatebucket' value='updatebucket' src='images/tick.png' /></form>";
}else{
echo "<form action='' method='post' name='updatebucket'><input name='complete' type='hidden' value=" .$complete. " /><input name='userid' type='hidden' value=" .$userid. " /><input name='bucketid' type='hidden' value=" .$bucketid. " /><input type='image' name='updatebucket' value='updatebucket' src='images/cross.png' /></form>";
}
?>
Dan
You should post your front-end, not back-end (since it's pretty much not browser-dependant).
Your HTML probably isn't valid.
Edit:
Yep, IE doesn't take value for image type of input. It only sends the x & y (field_name_x, field_name_y) and totally discards the original "value" attribute.
Try with a hidden input instead.
It seems that input type='image' doesn't send the value when used from IE. You'll need another hidden field:
<input type='hidden' name='updatebucket' value='updatebucket' />
<input type='image' src='images/tick.png' />
That way, the updatebucket parameter will be posted to the server, regardless of the browser used.
The assumption here was that all browsers handle HTML forms the same way (and they don't); that's why I keep Eric Lawrence's excellent Fiddler around - it can diff two HTTP requests, so you'll see the difference between the browsers immediately.
An alternative would be to check for $_POST[{image-element-name}_x}] (in this case $_POST['updatebucket_x']. All browsers will send the x/y coordinates of the image element as updatebucket.x & updatebucket.y, and PHP silently (and frustratingly) alters the updatebucket.x to updatebucket_x. Then again, you only need this is clicking different input type=submit / type=image elements would alter the action taken, otherwise the previous solution of a hidden element as previously suggested would do.