I've got a JQuery function running on my create page for my contacts list. User selects one of three radio buttons - individual, team and company. And will fill out different forms depending on which one they chose.
Individual sees all the fields below.
Team sees all but title.
Company sees but company and title.
When users edit between individual/company, the view.php will still --> if individual changes to company (thus not needing company/title) the company/title will still show because they a) haven't backspaced the values and b) technically isn't deleted. I'm fine with the criteria still sitting in the backend, but I want to add if statements to make sure that the individual is seeing the individual criteria, company seeing company criteria etc.
<body>
<div class="container">
<div class="row">
<table class="table">
<tr>
<th><strong>Name</strong></th>
<th><strong>Type</strong></th>
<th><strong>Details</strong></th>
<th><strong>Phone</strong></th>
<th><strong>Email</strong></th>
<th><strong>Address</strong></th>
<th><strong>Extras</strong></th>
</tr>
<?php
while($r = mysqli_fetch_assoc($res)){
?>
<tr>
<td class= "r-Name"><?php echo $r['Name']; ?></td>
<td class= "r-Type"><?php echo $r['Contact_type']; ?></td>
<td class="r-Details"><?php echo $r['Title']. ', '.$r['Company']; ?></td>
<td class="r-Phone"><?php echo $r['Phone']; ?></td>
<td class="r-Email"><?php echo $r['Email']; ?></td>
<td class="r-Address"><?php echo $r['Address']; ?></td>
<td class="r-Update">Edit</td>
<td class="r-Delete"><a href='delete.php?id=<?php echo $r['id']?>'>Delete</a></td>
</tr>
<?php } ?>
</table>
</div>
</body>
</html>
You can add this to your jquery code
$("yourinput_id").prop('disabled', true); //to disable
$("yourinput_id").prop('disabled', false);//to enable
/*so that the form will ignore the input when passed to php, regardless of
visibility*/
Related
An HTML table is given in which there are people (agents in this case) who have the following information displayed Id, Name, Rank, Location, and Status. Status can have 3 values. Online, Offline, Disconnected. Based on the status that one of the agents has I want to put 3 buttons as such Online, Offline, and Disconnected, and when a button is pressed to hide the other rows with different values. For example, if I press Online, table rows on the HTML side that contain the status Offline and Disconnected disappear, this goes for the others too the other way around. I have no idea to achieve what I said earlier and I am open to any solution that is deemed to resolve my problem.
<table id="main_table">
<tr>
<td>Id</td>
<td>Agent Name</td>
<td>Agent Rank</td>
<td>Agent Location</td>
<td>Status</td>
</tr>
<?php
require 'CMS/processing/conn.php';
$result = mysqli_query($con,"SELECT * FROM agents");
while($info = mysqli_fetch_array($result)) {
?>
<tr>
<td><?php echo $info['id']; ?></td>
<td><?php echo $info['agentName']; ?></td>
<td><?php echo $info['agentRank']; ?></td>
<td><?php echo $info['locationNames']; ?></td>
<td><?php echo $info['agentStatus']; ?></td>
</tr>
<?php
}
?>
</table>
Try using the below logic : Create 3 buttons with <a> and pass status value as GET to the same page then while fetching check whether it has GET or not
Note:This is not a answer :passing direct GET value to sql query may cause some security issues
Online//put the status value based on your status
Offline//put the status value based on your status
Disconnected//put the status value based on your status
<table id="main_table">
<tr>
<td>Id</td>
<td>Agent Name</td>
<td>Agent Rank</td>
<td>Agent Location</td>
<td>Status</td>
</tr>
<?php
require 'CMS/processing/conn.php';
if(isset($_GET['status']))
{
$result = mysqli_query($con,"SELECT * FROM agents where agentStatus='".$_GET['status']."'");
}
else
{
$result = mysqli_query($con,"SELECT * FROM agents");
}
while($info = mysqli_fetch_array($result)) {
?>
<tr>
<td><?php echo $info['id']; ?></td>
<td><?php echo $info['agentName']; ?></td>
<td><?php echo $info['agentRank']; ?></td>
<td><?php echo $info['locationNames']; ?></td>
<td><?php echo $info['agentStatus']; ?></td>
</tr>
<?php
}
?>
</table>
I'd use javascript within a tag or jQuery since this sounds like you need dynamic functionality on a static webpage.
For your button pass in the name of the function you're creating inside your tag
<button onclick="yourFunctionName(yourString)"></button>
Inside your tag have the function accept the yourString paramater
function yourFunctionName(yourString){
if(yourString === "whatever"){
$('tbody tr').hide()
$('tbody tr').show()
}
etc! Let me know if you need any more clarification on anything
Output echo an attribute on each row <tr data-status="online"> etc.
Then in script use document.querySelectorAll("tr[data-status='online'] to find all rows with that status, loop thru the array and toggle each row style.display to 'table-row' or 'none' as required.
You could also do the same using CSS by assigning a class <tr class="online"> etc. Then in script dynamically altering the CSS definition of that class, changing the display to 'table-row' or 'none' as required.
Hello and thanks for coming.
So I have the Category table with "n" values on it, and I have the table Price with "n" duplicated idCategorys (foreign Key) in it.
What I want to do is when selecting a Category from a dropdown menu a Html Table gets populated with all the prices with the Category i've chosen.
So far I've managed to get a dropdown select menu populated with php as follows:
<select name="categorias" required id="categorias" >
<?php $render = mysqli_query($con,"SELECT idCategoria FROM neomixlt_desarrollo.Categorias");
while($row1 = mysqli_fetch_array($render)) {
echo "<option value='" . $row1['idCategoria'] . "'>" . $row1['idCategoria'] ."</option>";
}
?>
</select>
And a table populated as follows
<table width="957" border="2" cellspacing="0">
<tr>
<th width="98" style="text-align: center">Categoria</th>
<th width="99" style="text-align: center">Articulo</th>
<th width="348" style="text-align: center">Precio a Domicilio(bs.)</th>
<th width="348" style="text-align: center">Precio en Planta(bs.)</th>
<th width="40" style="text-align: center"></th>
</tr>
<?php $render = mysqli_query($con,"SELECT * FROM neomixlt_desarrollo.precios_articulo WHERE idCategoria=$link ORDER BY idCategoria DESC ") or die(mysql_error()); ?>
<?php while($row1 = mysqli_fetch_array($render)):; ?>
<tr>
<td style="text-align: center"><?php echo $row1['idCategoria']; ?></td
><td style="text-align: center"><?php echo $row1['idArticulo']; ?></td>
<td style="text-align: center"><?php echo $row1['precio_domi']; ?></td>
<td style="text-align: center"><?php echo $row1['precio_plant']; ?></td>
<td style="text-align: center"><?php echo "<a href=editar_precios.php?pid=$row1[idArticulo]&cid=$row1[idCategoria]&precio_domi=$row1[precio_domi]&precio_plant=$row1[precio_plant]>editar</a>" ?></td>
</tr>
<?php endwhile; ?>
</table>
But they are not linked and I have not much idea on how to do this. im restricted to use php and html only and all similar examples I've found are using javascript or ajax, any idea? thanks in advance!
w/o JavaScript, JQuery, Angular, etc. available, you'll need to submit every time.
So load the page up in its original state, the user will choose their category. Now w/o JS available to go run updates nicely for you, you'll need to submit a form back to the server, then on the server side, get the POST category, and build the desired HTML and send that to the browser to view. This will have to be done every time they change categories.
Need help...
I have 2 php file which are screen1.php and screen2.php
screen1.php consist of main data and screen2.php consist of history of main data.
Both main data and history store in 1 table.
How do I work if, i click main data in screen1.php it load history data from screen2.php into screen1.php
Thank you
If all the data is in the same table then you just need to include the data in your query? If you wanted to keep your query simple you could use Ajax
This looks like a job for Ajax.
You will need to include jquery library for this.
Page: main.php?user_id=4
<!----include Jquery library----->
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<!----include Jquery library----->
<title>Main Data</title>
</head>
<body>
<?php $sql="SELECT username, date, account_number, status
FROM table WHERE user_id=" . $_GET['user_id'] ;
//Do a prepared Statement to avoid SQL injection. Here I will just keep things simple
$user=$db->query($sql)->fetch();
?>
<table width="100%" border="1" id="main">
<tbody>
<th colspan="4">Main Data</th>
<tr>
<td align="center"><strong>Username</strong></td>
<td align="center"><strong>Date</strong></td>
<td align="center"><strong>Account Number</strong></td>
<td align="center"><strong>Status</strong></td>
</tr>
<tr>
<td><?php echo $user['username']//James Bond ?></td>
<td><?php echo $user['date']//18 Jan 2015 ?> </td>
<td><?php echo $user['account_number']//58241687929876 ?> </td>
<td><?php echo $user['status']//Active ?> </td>
</tr>
</tbody>
</table>
<button id="view_more">View more</button><!---give button a id--->
<div id="history">
<!------New data will be added here------>
</div>
<!------- THIS IS THE MAGIC PART ----------->
<script>
$(document).on('click','#view_more',function(){
//Event, button ID
$.ajax({
url:"view_history.php?user_id=<?php echo $_GET['user_id']; ?>"
//Link to history.php. Pass user_id to url
success:function(data){
$('#history').empty();
//empty history div if there is anything
$('#history').append(data).hide().fadeIn(500);
//And then append new data
}
});
});
</script>
<!------- THIS IS THE MAGIC PART ----------->
</body>
Page: history.php
<?php
$sql="SELECT type,date FROM table WHERE id=" . $_GET[user_id];
$history=$db->query($sql)->fetch();
?>
<table width="100%" border="1">
<tbody>
<th colspan="4">History of James Bond</th>
<tr>
<td align="center" width="50%"><strong>Type</strong></td>
<td align="center"><strong>Date</strong></td>
</tr>
<tr>
<td><?php echo $history['type'];//Fund ?></td>
<td><?php echo $history['date'];//18 Jan 2015 ?></td>
</tr>
<tr>
<td><?php echo $history['type'];//Refund ?></td>
<td><?php echo $history['date'];//21 Jan 2014 ?></td>
</tr>
<tr>
<td><?php echo $history['type'];//Refund ?></td>
<td><?php echo $history['date'];//22 Jan 2014 ?> </td>
</tr>
</tbody>
</table>
Please be careful take care of security measures.
I have a database of players and their info in mysql. I have created a table in dreamweaver displaying all the players and their info. I want to display a player profile (which is stored in mysql) seperate from this table and want this information to change when the mouse is over a player in the table.
Is this possible and how do i go about it? Any help or links to tutorials will be greatly received!
I have a Screenshot of my page but am unable to post due to reputation if anyone wants to visualise my idea maybe i could send it them?
<div class="playerInfoContainer">
<table width="95%" border="0" cellpadding="3">
<caption>
Player Profile
</caption>
<tr>
<td><?php echo $row_Recordset1['PlayerProfile']; ?></td>
</tr>
</table>
</div>
</div>
<div class="squadListContainer">
<div class="DatabaseContainer">
<table width="95%" border="0" cellpadding="3">
<caption>
Bedlinog Veterans Squad
</caption>
<tr>
<th scope="col">Player Name</th>
<th scope="col">Position</th>
<th scope="col">Date of Birth</th>
<th scope="col">Points Tally</th>
<th scope="col">Man of the Matches</th>
</tr>
<?php do { ?>
<tr>
<td width="130"><?php echo $row_Recordset1['PlayerName']; ?></td>
<td width="100"><?php echo $row_Recordset1['Position']; ?></td>
<td width="100"><?php echo $row_Recordset1['DateOfBirth']; ?></td>
<td width="100"><?php echo $row_Recordset1['PointsTally']; ?></td>
<td width="100"><?php echo $row_Recordset1['MOM']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
</div>
Firstly, pre-build all of the displayed mouse-over data into separate XML/JSON files. That way there's no load on a database to display 15 items at once when someone goes nuts with their cursor.
Secondly, use jquery to display a mouseover event to populate a div on the page with the separate HTML files.
As long as your jquery is correct and your css skills are up to snuff, the details will change as required and maintain the correct look/feel as it goes from one 'team/squad' to the next.
EDIT: Solved - was not flutter's tag stripping, should work as advertised.
I'm using Flutter (which creates custom fields) in Wordpress to display profile information entered as a Post. Before I implemented the CSS tables the link showed up and was clickable. Now I get nothing returned, even when I try to call the link outside the table.
If you know anything about this, here's my code in the index.php file and I remain available for any questions.
<?php if (in_category('Profile')) { ?>
<table id="mytable" cellspacing="0">
-snip-
<tr>
<th class="row1" valign="top">Website </td>
<td>Link: <?php echo get_post_meta($post->ID, 'FrWebsite', $single=true) ?></td>
</tr>
-snip-
</table>
Edit: #Josh - there is a foreach looping construct in the table and it is reading and displaying the code correctly, I see what you're getting at now:
<tr>
<th class="row2" valign="top">Specialities </td>
<td class="alt" valign="top"><?php $my_array = get('Expertise');
$output = "";
foreach($my_array as $check)
{
$output .= "<span>$check</span><br/> ";
}
echo $output; ?></td>
</tr>
Edit - #Josh - here's the old code as far as I can remember it, there was no major difference just a <td> tag where there now stands a <th>, there wasn't the class="" and there was no "Link:" and FrWebsite was called Website, but it still didn't work when called Website so I changed to see if that was the error.
<tr>
<td width="200" valign="top">Website </td>
<td><?php echo get_post_meta($post->ID, 'Website', $single=true) ?></td>
</tr>
Where is $post set? What does the full table look like? Could be that when you changed the table structure you accidentally removed something like (line 2 below):
<table id="mytable" cellspacing="0">
<?php foreach($posts as $post) { ?>
<tr>
<th class="row1" valign="top">Website </td>
<td>Link: <?php echo get_post_meta($post->ID, 'FrWebsite', $single=true) ?></td>
</tr>
<?php } ?>
(Just guessing here...)