PHP redirect URL - javascript

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>

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

fetch data without reloading by passing a variable to jquery

I want to fetch some data (without reloading page) based on UserIds that are linked to a tags. I am not able to pass on UserID to jquery successfully and accurately. What it does is, just picks the last UserID and fetches it.
I have also tried to pass on variable throuh a-tag URL but could not get it accurately in jquery file. It fetches the data from already opened url, not the one being clicked right now.
HTML:
<?php foreach($Messagers as $Messagers1){ ?>
<form action="" method="post">
<input type="hidden" id="ANP" value="<?php echo ($Messagers1['UserID']*3);?>"></input>
<a class="LoadMsgsBtn">
Click to load data
</a>
</form>
<?php}?>
<div id="result">
<--The output will come here!-->
</div>
jquery:
$(document).ready(function(){
$(".LoadMsgsBtn").click(function LoadMsgsfunc(){
var ANP = $("input#ANP").val();
var Msg=6;
alert(ANP);
$("#result").load("LoadDB.php",{
ANP: ANP,
Msg: Msg
});
})
});
LoadDB.php:
<?php
$ID = $_POST['ANP'];
$Msg = $_POST['Msg'];
echo $ID . "\n";
echo $Msg;
I want to fetch data from database without reloading using UserID sent. $Messager is an array having multiple rows, there is a series of a-tags. clicking on any a-tag sents corresponding UserID to jquery code
Classic issue of multiple element selection. It's a bit tricky when you are using loops and jquery selectors ;) Check out the following code. It should work like butter B)
<?php foreach($Messagers as $Messagers1){ ?>
<form action="" method="post">
<a class="LoadMsgsBtn" href="javascript:void(0)" onclick="featchData('<?php echo ($Messagers1['UserID']*3);?>')">
Click to load data
</a>
</form>
<?php}?>
<div id="result">
<--The output will come here!-->
</div>
Javascript
function featchData(userId)
{
console.log(userId);
//if you get the id, write in the rest of the code here ;)
}

Passing $data variable to iframe from controller in CodeIgniter

I want to display a page in iframe. This page contains email contents since I am building an inbuilt email system. But the CSS of the email contents are overriding my CSS styles. Now this page gets some data from $data variable which I Pass through controller.
To avoid getting my CSS style issues I am thinking of displaying that page in an iframe. (If anybody has any other solutions, welcome).
inboxdetailspage.php --> View which displays email contents
mailactions.php --> controller which passes $data to inboxdetailspage.php
This is the function that does it.
function viewInboxDetails(){
$mailId = $this->uri->segment('4');
$data['emailInfo'] = $this->fetchParticularEmailInfo($mailId);
$data['titleText'] = 'Email Information';
$this->load->view('admin/inboxdetailspage',$data);
}
I am absolutely blank on how to achieve this feature
Passing data to the IFRAME from the same controller is not possible.
IFRAMEs' are just basically another URL display on a particular page. Hence all you can do is can pass the data via URL and thats it!
How this can be achieved this is create another (say) link for displaying the mail content by taking the ID from the URL and display that URL in iFrame. For example,
Controller:
public function all_mails()
{
$data['mails'] = $this->xyz_model->get_mails();
$this->load->view('all_mails.php', $data);
}
public function mail_content($mail_id)
{
$data['mail'] = $this->xyz_model->get_mail_content($mail_id);
$this->load->view('mail_content.php', $data);
}
View:
all_mails.php
<?php foreach($mails as $mail) { ?>
<table>
<tr>
<td><?php echo $mail->from; ?></td>
<td><?php echo $mail->subject; ?></td>
<!-- Your email content -->
<td>
<iframe src="/xyz/mail_content/<?php echo $mail->id; ?>"></iframe>
</td>
</tr>
</table>
<?php } ?>
mail_content.php
<!-- Your CSS here -->
<link href="/static/home/css/bootstrap.min.css" rel="stylesheet">
<div>
<?php echo $mail->content; ?>
</div>
First pass $data to your view and from there call another controller which can render your whole iframe from it with its own view.
Create an iframe in the view linking to another function in controller(a new page). In this page display only email contents according to the email.

Common popup form, generated table

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
?>

Updating session variable using onclick in php

I am trying to update the $_SESSION['state'] whenever the user clicks on the anchor tag by firing the onclick event. The variable $state_names_array as all the names of the states of a specific country. But problem is that no matter whichever of the anchor tag I click on, the $_SESSION['state'] is always getting updated by the last element of the $state_names_array.
<?php
foreach($state_names_array as $value){
$temp = '<?php $_SESSION["state"]=$value;?>';
?>
<?php echo $value ?><br>
<?php
}
?>
I will not code whole code, I will just show you an example, how to do it:
<?php
foreach ($state_names_array as $value) {
echo ''.$value.'<br>';
}
?>
Then you will have javascript function change_value:
here you will send ajax call to some PHP file, where you will process $_SESSION["state"]=$value;
Also you didnt say, what you want after anchor is clicked, because you will be able to access new $_SESSION["state"] only after refreshing your site...
Also maybe you just want to redirect to index.php, after clicking on some anchor, and that will be enough for you, then just use value as $_GET parameter, f.e.:
<?php
foreach ($state_names_array as $value) {
echo ''.$value.'<br>';
}
?>
and add to you index.php file this lines:
if (isset($_GET['new_value'])) {
$_SESSION["state"] = $_GET['new_value'];
}

Categories

Resources