Here I am counting the number of persons a profile owner is following, and the output number is link to open a new page were all persons being followed will be displayed, the count works well and gives the number of persons being followed but now to complete my next page say following.php where all persons being followed will be displayed I need to pass variable $id to that page for which I want to use url method, please help me on this.
<?php
$checkfollowing =$db->prepare("SELECT * FROM follow_user WHERE uid_fk=:id");
$checkfollowing->execute(array(':id'=>$id));
$count = $checkfollowing->rowCount(); ?>
<a href='following.php' style='text-decoration:none;margin-left:40px;'><?php print $count; ?></a>
you can pass value by url and get the value on other page by using $_GET method.
check the below code.
<a href='following.php?id=<?php echo $id ; ?>' style='text-decoration:none;margin-left:40px;'><?php print $count; ?></a>
<a href='following.php?id=<?php echo $id; ?>' style='text-decoration:none;margin-left:40px;'><?php print $count; ?></a>
you can pass a variable through url by specifieng your variable at end of your url. like this
<a href='following.php?count=<?php echo $count; ?>' style='text-decoration:none;margin-left:40px;'><?php print $count; ?></a>
Related
I am using jqxgrid in codeigniter to display records from mysql database. while displaying the data, I made a column named 'action' that contains edit a tag to redirect to another page for editing a specific record. I need to assign id to href attribute in order to do that. but I can't correctly do that.
In controller, tax.php:
foreach($result as $row){
$data[$i]['tax_id']=$row['tax_id'];
$data[$i]['tax_name']=$row['tax_name'];
$data[$i]['action']='Edit';
$i++;
}
how can i correctly assign tax_id to my URL?
I believe you have to evaluate $row["tax_id"] as a PHP expression:
$data[$i]['action']='Edit';
Edit: Use PHP's string concatenation to construct the <a> element:
$data[$i]['action']='Edit';
This is how you do it.
<?php
foreach($result as $row)
{
$editurl = base_url() . 'admin/edit-user/' . $row['tax_id'];
?>
<a href="<?php echo $editurl; ?>" class="edit-user" >Edit</a>
<?php
}
?>
Do let me know if it didn't work.
Use below code:
$id = $row["tax_id"];
$data[$i]['action']='Edit';
It will work properly.
Use the page1.php and page2, page3 examples in chapter 23 as template. Create a fourth and fifth page participating the session. On each page, show links to all the other pages (it is OK to include a link to the current page).
On each page, display a list of all pages you visited during this session as shown below.
Pages display
-You may use the Superglobal variable $_SERVER[“PHP_SELF”] to access the name of the current page.
-To declare an empty array use syntax: $some_array = [];
-To append to this array: $some_array[] = ‘Appended string’;
you may use foreach() to retrieve the content of the session array
Please help me on how to display the list of pages as shown in the example above.
So far I came up with this code to get the display that is shown in the picture but I am getting errors.
<?`php`
session_start();
// .$_SESSION['`sess`_var'].'<`br` />';
$array_var = [];
$array_var[]= 'tom';
$array_var[]='`alice`';
$array_var[7] = 'Smith';
echo $_SERVER['`PHP`_SELF'];
$_SESSION['name'] = 'Tom Smith<`br`>';
// echo $_SESSION['name'];
echo '<a `href`="page1.`php`?p1">Page1.`php`</a>';
echo '<a `href`="page2.`php`?p2">Page2.`php`</a>';
echo '<a `href`="page3.`php`?p3">Page3.`php`</a>';
echo '<a `href`="page4.`php`?p4">Page4.`php`</a>';
echo '<a `href`="page5.`php`?p5">Page5.`php`</a>';
$i=0;
if(`isset`($_GET['p1']))
{
$file_array[$i]="page1.`php`";
$i++;
}
if(`isset`($_GET['p2']))
{
$file_array[$i]="page2.`php`";
$i++;
}
if(`isset`($_GET['p3']))
{
$file_array[$i]="page3.`php`";
$i++;
}
if(`isset`($_GET['p4']))
{
$file_array[$i]="page4.`php`";
$i++;
}
if(`isset`($_GET['p5']))
{
$file_array[$i]="page5.`php`";
$i++;
}
echo "The pages you visited are :";
for($i=0;$i<=$file_array[$i];$i++)
{
?>
<`br`/>
<a `href`="page1.`php`">Page 1</a>
<a `href`="page2.`php`">Page 2</a>
<a `href`="page3.`php`">Page 3</a>
<a `href`="page4.`php`">Page 4</a>
<a `href`="page5.`php`">Page 5</a>
Refer to the code below
$uri = $_SERVER['REQUEST_URI'];
array_push($_SESSION['uriHistory'], $uri);
This would get the current uri of the page and add that to the PHP SESSION variable. You can simply add this before all your pages. To get the list of pages visited simply print the $_SESSION['uriHistory'] variable.
Needless to say you need to start session for the code to run properly.
I am trying to implement pagination functionality to a page. I have custom post types and I have looped through and gathered all the posts for this page. I display the first post and hide the rest and I have next/previous buttons that will show the next post and hide the current post. It seems to be working, however I am not able to view all the posts - only 2 of them.
Here is my code:
<?php
$currProj = 1;
$countposts = 3;
?>
<?php if ($countposts>1) {
$prevID = $currProj - 1;
if ($prevID <= 0) {
$prevID = $countposts;
?>
<a class="btn-previous" href="javascript:showProject('<?php echo $currProj; ?>','<?php echo $prevID; ?>')" onclick="<?php $currProj=$prevID; ?>"> < Previous </a>
<?php } else {
?>
<a class="btn-previous" href="javascript:showProject('<?php echo $currProj; ?>','<?php echo $prevID; ?>')" onclick="<?php $currProj=$prevID; ?>"> < Previous </a>
<?php
//$currProj = $prevID;
}
echo $currProj; //This outputs 3 where it should be 1
$nextID = $currProj + 1;
if ($nextID > $countposts) {
$nextID = 1;
?>
<a class="btn-next" id="nextlink" href="javascript:showProject('<?php echo $currProj; ?>','<?php echo $nextID; ?>')" onclick="<?php $currProj=$nextID; ?>"> Next > </a>
<?php } else {
?>
<a class="btn-next" id="nextlink" href="javascript:showProject('<?php echo $currProj; ?>','<?php echo $nextID; ?>')" onclick="<?php $currProj=$nextID; ?>"> Next > </a>
<?php
//$currProj = $nextID;
}
} ?>
The javascript function is working correctly, the issue seems to be the $currProj variable. I think the issue is my onClick attribute in the tag - is there a better way of having an onClick event that will give my variable a different value? Or a way of checking if this link has been clicked then give the currProj the value of prevID/nextID ?
I have been stuck on this for a while now and I don't seem to be getting anywhere. Any help would be greatly appreciated.
Your code above seems to be conflating what's happening on the server side and what's happening on the client side. Anything wrapped in <?php ... ?> is going to be executed on the server and then sent to the client as HTML -- for example, this line:
<a class="btn-previous" href="javascript:showProject('<?php echo $currProj; ?>','<?php echo $prevID; ?>')" onclick="<?php $currProj=$prevID; ?>"> < Previous </a>
will end up being sent to the client with all of the PHP interpreted:
<a class="btn-previous" href="javascript:showProject(1,3)" onclick=""> < Previous </a>
The key thing here is this you're not re-running the PHP when you click -- the client is completely agnostic to the PHP ever having been there. Every time you click the Previous button, its href attribute is still javascript:showProject(1,3).
You have two options; namely, you can go back to the server and have it re-render the page whenever you click the next / previous button by including those variables as parameters to your page, e.g., get the current project from the URL and link like so:
$currProj = ( $_REQUEST['currProj'] ? $_REQUEST['currProj'] : 1 );
...
<a class="btn-previous" href="<?php echo '[your_url_here]?currProj=' . $prevID ?>">
However, it looks like you're interested in doing this without ever pinging the server again. In that case, you'll need to store, reference, and update these variables in javascript. There are probably a thousand ways to do this; the closes to what you seem to want to do would be to have your showProject function take no arguments and instead figure out what it needs to do based on the value of the current project, something like
var currProj = <?php echo $currProj; ?>; // this initializes the JS variable currProj from whatever it is in PHP when the server sends the page contents
var countposts = <?php echo $countposts; ?>; // initialize this too
var showPrevProject = function showPrevProject() {
// hide the current project using jQuery; assumes the DOM element you want to hide is given ID #project-[currProj]
$('#project-' + currProj).hide();
// Update the current project variable in JS; scope should update globally
currProj = currProj - 1;
if (currProj === 0) { currProj = countposts; }
// Now show that element
$('#project-' + currProj).show();
}
Then in your link you can use showNextProject or showPrevProject as appropriate.
More generally, though, it's probably better to include your javascript as a separate file and register event handlers to deal with this sort of thing. I would also recommend checking out jQuery, which is a powerful library that greatly simplifies accessing and manipulating DOM elements.
What about creating a HTML hidden input for storing those values?
<input type="hidden" value="<?php echo $currProj ?>" id="currProj">
So you can access it and modify it in client side with javascript or jQuery. If you want a solution server-side you can do it with ajax and POST or GET requests.
Maybe this isn't what you are looking for (modify the php attributes) and I misunderstood you. Let me know if this is your case.
I have a page that displays a lot of data, including Zend_Paginator.
The page action is /po/fetch?id=someID.
what i want to do is to pass the "id" parameter to zend paginationControl so the pagination links will be something like /po/fetch?id=someID&page=somePage. unfortunally i can't find anywhere explanation on how i can pass that parameter to the paginationControl.
my call to paginationControl:
echo $view->paginationControl($paginator, 'Sliding',$control, $params);
where $params = array('id' => someID
and my pagination partial is:
First
< Previous
<?php
foreach($this->pagesInRange as $page) {
?>
.$page. | ;
<?php
}
?>
Next >
Last
and I want $url to be of the specified form.
$this->id
Hey Try this, It will surely work.....
<a href="<?php echo $this->url(array('page' => $page,'id'=>'1')); ?>">
<?php echo $page; ?>
</a>
Here 1 is given as the id you have to pass the id you want.......
Like
<a href="<?php echo $this->url(array('page' => $page,'id'=>$param['id'])); ?>">
<?php echo $page; ?>
</a>
Your example code doesn't show how $url is populated, but you really should be using the URL ViewHelper.
So, for example - your previous link would become:
< Previous
This will return a proper URL to the current page with the page parameter set to $this->previous. So if the current url is /users/view?foo=bar&page=5, the above code would output /users/view?foo=bar&page=4 for the previous link. Notice how any query parameters that are already present are preserved.
So, if the id parameter is already present on the URL showing your paginator, the above code will "just work". However, if you still need to add the id parameter, you can do so like this:
< Previous
To continue from our previous example, this code would output the following url: /users/view?foo=bar&page=4&id={someId}
Here is the reference documentation for the URL ViewHelper:
url($urlOptions, $name, $reset):
Creates a URL string based on a named
route. $urlOptions should be an
associative array of key/value pairs
used by the particular route.
One last note - the $reset (third) parameter of the URL ViewHelper will come in very handy. The default behavior is to preserve any query parameters of the current request but calling $this->url(array(), 'default', true) with true for the $reset parameter will basically remove all parameters except for the ones you specify in $urlOptions.
I have gone through the same issue so I have used code given below in partial paginator.
I have created a function in paginator partial view file(control.phtml) or may be different.
function queryStr($p){
$params = $array = Zend_Controller_Front::getInstance()->getRequest()->getQuery();
$params['page']=$p;
$str='?';
foreach($params as $k=>$v){
if($v)
$str .= $k.'='.$v.'&';
}
return $str;
}
Now for links I am using code given below.
<a href="<?php echo queryStr($page); ?>">
Instead of
<a href="<?php echo $this->url(array('page' => $page)); ?>">
I am sure it will be helpful to others as well.
I would like to set values on an url like this:
<a href='http://$data_url/viewyournote.php?chapter='$name_of_chapter'¬e='$id_note'&user='$username'>
Then be able to grab then from the recieving page.
Right now all im getting is this when clicked:
http://localhost/readnotes/viewyournote.php?chapter=
I don't how you embed your link in your code, but if it is outside of <?php ?> tags, then you have to do:
<a href="http://<?php echo $data_url ?>/viewyournote.php?chapter=<?php echo $name_of_chapter ?>¬e=<?php echo $id_note ?>&user=<?php echo $username?>" >
if it is inside these tags, you can also do:
echo "<a href='http://$data_url/viewyournote.php?chapter=$name_of_chapter¬e=$id_note&user=$username?' >";
You can get these values on the recieveing page with $_GET['variable_name_here'], e.g. $_GET['chapter'].
Use Query string
$val = "yourvalue" ;
$url "http://localhost/readnotes/viewyournote.php?chapter=$val";
Now $val is passed to specified url .
There you could get it by using $_GET['chapter'] , It will give you "yourvalue"
<a href='http://$data_url/viewyournote.php?chapter=<?php echo $name_of_chapter; ?>¬e=<?php echo $id_note; ?>&user=<?php echo $username; ?>>
Replace your line with
<?php
echo "<a href='http://$data_url/viewyournote.php?chapter='$name_of_chapter'¬e='$id_note' user='$username'>";
?>
On the receiving end use
<?php
$name_of_chapter = $_GET['chapter'];
...
?>