Common popup form, generated table - javascript

My Web page generates a table that shows the results of a search. I want the user to be able to click on one of the results, have a pop up window which allows them to enter a message and have it stored on a database. Then the user clicks the send message button, the popup will then close and let the user continue the search results.
Here is the current code I have.
<h1>
<center>
<u>Casting Call Results</u>
</center>
</h1>
<table border="1"; width="600px"; align="center">
<?php if(empty($results)) {echo "No Data returned";} ?>
<?php foreach($results as $member):?>
<?php $imgloc = "members/".$member['username']."/".$member['photolink'];?>
<tr align="center">
<td width="100px"> <img style="width:100px; height:125px" src="<?php echo $imgloc;?>"></td>
<td><?php echo $member['bio'];?></td>
</tr>
<tr align="center">
<td><?php echo $member['username']?></td>
<td><?php echo $member['email']?></td>
</tr>
<?php endforeach; ?>
</table></div>
<form action="castingcall.php">
<center><input type="submit" value="Search Again"></center>
</form>
Here's the search return. I tried to insert the image but I don't have ten reputation points so here's a link to the search return so you can see what I'm talking about.
http://www.chicagofilmclub.org/screenshot.jpg
As you can see the table is generated by a for each so I am really confused as to how I can have each user an active link that calls the same page in a popup but can still $PASS the proper user name.

Each person would have a link that would look something like this:
Contact Member
I am assuming you will give each memebr an ID in your database.
Then on the contactform.php page you would use something like this:
<?php
$memberId = $_GET['member'];
//lookup memeber in database and do whatever it is you want to do with that info
?>

Related

Load search result php url in div on same page

I have search results and am displaying them in div on left of page. When user clicks on the a particular result (which is a link), it needs to open on the right of the page, without refreshing the page or moving to a new page. How does one do this?
//get rows
$query = $db->query("SELECT * FROM posts ORDER BY id DESC LIMIT $limit");
if($query->num_rows > 0){ ?>
<div class="post_list">
<?php
while($row = $query->fetch_assoc()){
$postID = $row['id'];
?>
<div class="list_item"><h2><?php echo $row["title"] ?></h2></div>
<?php } ?>
</div>
<?php echo $pagination->createLinks(); ?>
<?php } ?>
</div>
</div>
</body>
</html>
You are going to have an onclick listeners on each <a> which will take your file/file.php?id= as input to an ajax call to fetch the contents at file/file.php?id=.
I am not sure how familiar you are with Javascript, if you know it very well then you'll undersntand what I said above, if you don't then please find documentation about AJAX some ajax documentation
You might also want to find documentation on stuff like innerHTML dom manipulation

PHP redirect URL

I have successfully directed my users to a page that contains their information from a table. Using this code:
<?php foreach ($customers as $row) : ?>
<td onclick="window.location='view_customer.php?customer_id=<?php echo $row['id'] ?>&operation=edit';">
</td>
<?php endforeach; ?>
Now they are on view_cutomer.php. The next step would be to redirect the users to another page that also contains their information (the same information). Using a button. The next page is paint.php. I've tried this code, but it does not seem to work. Btw this next page no longer has a table.
<button onclick="window.location='paint.php?customer_id=<?php echo $row['id'] ?>&operation=edit';" class="rbutton">Paint</button>
How do i redirect users to a specific page using their ID?
on the 2nd page the id you want is in the get array (from the url)
<button onclick="window.location='paint.php?customer_id=<?php echo $_GET['customer_id'] ?>&operation=edit';" class="rbutton">Paint</button>

is it possable to prevent PHP $var from reseting?

Im fairly new to PHP and I'm currently working on a battle system, kind of like an idle clicker game, and not sure how to handle somethings do to lack of knowledge. What i am attempting right now is a player clicks a button , that POSTs Attack, and the damaged is taken from enemy hp, but what going on is every time i submit the attack, the HP get reset which is to be expected from PHP, I just don't know how avoid it resetting without having the value stored in a database which im trying to avoid just to keep the work load on the server light. I thought maybe moving the $VAR to my header.php but again it still get reset.
<?php
session_start();
include("header.php");
if(!isset($_SESSION['uid'])){
echo "You must be logged in to view this page!";
}else{
if(isset($_POST['attack'])){
$health--;
}
?>
<form action="battlesystem.php" method="post">
<table cellpadding="5" cellspacing="5">
<tr>
<td><input type="submit" name="attack" value="Confirm"</td>
<td><?php echo number_format($health); ?></td>
</tr>
</table>
</form>
<hr />
<?php
}
include("footer.php");
?>

Pop up menu to show detail view of contact in contact manager

I have queried data from DB depending on user input and viewed that on a table.
There is a column in my table, it will include id of each row as a link.
When I click that link it should show a pop up menu with full details of that particular row contact.
I want to pass that id to new pop and query full details from DB and show that in the pop up. Please help me with this.
Following is my current table population depend on queried data:
<tr valign="middle">
<td><?php echo $row["last_name"];?></td>
<td><?php echo $row["calling_name"]; ?></td>
<td><?php echo $row["designation"]; ?></td>
<td><?php echo $row["agm_branch"]; ?></td>
<td><?php echo $row["dgm_branch"]; ?></td>
<td><?php echo $row["office"]; ?></td>
<td><input type="submit" name="button" id="<?php echo $row["id"];?>" value="Details" onClick="showpopup()"></td>
</tr>
Now I need to write appropriate code in this java script
function:
function showpopup() {
//get passed variable if any (id)
//include database config details
//query data base depend on passed id
//show the results on form or table
//close button
}
I'm a bit rusty on Javascript/Jquery but here's some changes i would make
Put the id as a argument to your JS function
function showpopup(id){
...//your code here
}
This means that you also need to echo in the call of the function
onClick="showpopup(<?php echo $row["id"];?>)">
You said you want to query more details. If you haven't got the details on this page ready to go then you can use an ajax call to a php script that can get the details and return the data.
Some reading:
jQuery ajax calls
JSON syntax

How to print a html table in a separate window

I want to print a HTML table using some PHP data, in a separate window when I press a button. What is the best way to do it?
<table border="1">
<tr>
<td>MODEL</td>
<td><?php echo $modelNo ?></td>
<td>MODEL</td>
<td><?php echo $modelNo ?></td>
</tr>
<tr>
<td>QTY</td>
<td><?php echo $box ?></td>
<td>QTY</td>
<td><?php echo $box ?></td>
</tr>
</table>
Have the button open the new window, and set its location to the PHP file that prints the table.
Something as simple as this could work:
Click
(You can optionally style this link to look like a button)
You will need to have this table returnable from a PHP script, or available somewhere (I assume you already do).
Here is a purely html method:
Open Table!
Here is a javascript method:
<script type="text/javascript">
<!--
function myPopup() {
window.open( "http://path.to.my.page.com/mypage.php" )
}
//-->
</script>
</head>
<body>
<form>
<input type="button" onClick="myPopup()" value="Open table!">
</form>
<p onClick="myPopup()">CLICK ME TOO!</p>
You can also have the html in a hidden input and use a form submit to the other page and retrieve it from there with $_POST like assuming $table_data is your html:
<form action="new_window.php">
<input type="hidden" value="$table_data" name="data">
<input type="submit" value="Open Table">
</form>
Then in new_window.php:
if(isset($_POST['data'])){
echo $_POST['data'];
}
You can also create the entire solution in javascript by creating a new window and by writing the content in the window.
see the basic approach writing in a new window here:
http://www.w3schools.com/jsref/met_win_open.asp
and
Print the contents of a DIV
You would have to add an id attribute to your table
Then playing with DOM functions such as :
https://developer.mozilla.org/en-US/docs/DOM/document.getElementById
and
https://developer.mozilla.org/en/docs/DOM/element.innerHTML
You will have to wrap your table into a html. The main advantage of this method is that it can be called later on any table without the need to add a line of php.

Categories

Resources