TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   How to go to a particular page when i click on a particular word? (http://www.talkphp.com/absolute-beginners/4669-how-go-particular-page-when-i-click-particular-word.html)

sandhyagupta 07-02-2009 02:28 PM

How to go to a particular page when i click on a particular word?
 
Hi,

I am in a particular page and this page displays few tables. when i click on a particular work i wanna go to a different page whose url would be something like this :

http://www.konanakunteokkoota.org/applyhereforjob.php?username=$username&post_id=$po stid

Can any one tell me how to do this?
Thanks in advance.

Village Idiot 07-02-2009 03:01 PM

You will need to be more clear in what you are doing, are you looking for instructions on how to dynamically create links? Where will the data be coming from?

codefreek 07-02-2009 03:02 PM

Thread moved to:
Absolute Beginners

Village Idiot 07-02-2009 03:02 PM

Quote:

Originally Posted by codefreek (Post 26480)
Thread moved to:
Absolute Beginners

Haha, that would explain why it wouldn't let me do it.

codefreek 07-02-2009 03:06 PM

@Village Idiot, sorry hehe ;)

@sandhyagupta, please let us have some more,
info on what your after,
so we can help out :) as Village Idiot, said.

tony 07-02-2009 04:13 PM

can't you just create a link and echo it to the page?

PHP Code:

echo '<a href="http://www.konanakunteokkoota.org/applyhereforjob.php?username='.$username.'&post_id='.$po stid.'">Word</a>'

This is just without knowing what exactly is the situation, or where are you getting the data form, or how do you want/need to output the link. Or maybe you already have some script that we can look at
Like Village Idiot and codefreak said, we need more information to help you out.

codefreek 07-02-2009 09:17 PM

Quote:

Originally Posted by tony (Post 26489)

PHP Code:

echo '<a href="http://www.konanakunteokkoota.org/applyhereforjob.php?username='.$username.'&post_id='.$po stid.'">Word</a>'


So, i might have just posted with a haste, i shall explain my opinion on your quote why, i don't agree on the use of that, 2 reasons, well first, the page load could suffer a big lose if you have a lot of links that are like that, and also safe coding, correct me if i am wrong please do : )

-Cf

Salathe 07-02-2009 09:21 PM

Quote:

Originally Posted by codefreek (Post 26494)
not a safe way to print out links like that :)
i might add..

No-one said anything about the variables coming from user input. Please explain, while you're happy to add random points to a thread, why the code you quoted is not safe. :-/

sandhyagupta, whether you know it or not, your post was very vague and we really have nothing to go on with regards to understanding your problem and therefore nothing for us to help you with. Please come back and add some more detail to let us know exactly what you're wanting to do.

codefreek 07-02-2009 09:34 PM

I offered my opinion on a post..

//add random points ??, - all thoughts shall be made even if it is not that
useful at that exact time, it is still a community of helping am i not right ?

in my opinion i feel that a page with links like that could, slow it down as well be unsafe, but if i said something that is false, or so on, i am far away from being a php pro, but i do say safe php from the start or even have safe ways to code for example, code that could make a page slow, but please do correct me if i am wrong, no need to (flame up, on something i say)

Salathe 07-02-2009 10:24 PM

You make two claims.
  1. Concatenating strings like that will impact on page performance.
    Please clarify why you think this. Have you read some information on this subject which makes the claim, or done some profiling and benchmarking? What more performant alternatives would you use to replace that line of code?
  2. Coding in that manner is somehow unsafe.
    Now, I think that I know where you're coming from on this. The idea is that throwing variables blindly into HTML could, in theory at least, result in the ability to exploit that piece of code (injecting malicious code, for example). However to claim that any code using plain variables concatenated with HTML strings is somehow insecure, I think that's stretching it a bit. Again, what would you do instead of the quoted line of code which would make it much more safe?

Tanax 07-02-2009 10:42 PM

Gee. Stop fighting. He was just stating his input, if he's incorrect, just post that in a commonly fasion.

When dealing with variables in links(or in any type of string - like an SQL query), I use sprintf. In this case:

PHP Code:

$link sprintf("http://www.konanakunteokkoota.org/applyhereforjob.php?username='%s'&post_id='%d'",
secure($username),
$post_id);

echo 
'<a href="' $link '">Word</a>'

Where secure is a function where you do the regular string-security checks(mysql_real_escape_string, stripslashes.. etc).

codefreek 07-02-2009 10:44 PM

on nr 2 on your list/question, i would say at least use sprintf..

cecilia 07-02-2009 11:42 PM

I think I would do this just like what tony said, to just directly concatenate it to all of them then echo it in one go, all of the links. After you do the sanitation on both variables that is. I mean im assuming theres like a hundred or something of em, the links.

I have read somewhere that echoing something is slower than directly outputting it outside of php, but as for what Salanthe was asking, I have no idea how much the difference is. I think I said something similar somewhere and was answered that the difference was miniscule or something that it wont matter that much.

Salathe 07-03-2009 10:13 AM

Quote:

Originally Posted by Tanax (Post 26512)
Gee. Stop fighting.

Hehe, fighting. There needs to be two sides to fight, all I'm asking for is clarification on the points he raised. If anything, I'm trying to promote healthier discussion here by asking for more than one-line "this is bad" or "this is what you should do" comments. One might see that as fighting, perhaps, but it's not the intention at all.

I still fail to see why the quoted code should be non-performant and insecure which is why I'm pushing for codefreek's own thoughts. It's not about right and wrong (there probably isn't such a clear distinction anyway) but just about making claims without putting them in context. Why do you think the code would be slowed down, what would you suggest instead? Why do you think the code is insecure, what would you suggest instead?

sandhyagupta 07-03-2009 11:14 AM

I will want to click on any of the postions displayed in my table and then it has to direct me to that page depending on the postion. Hope i am clear this time.

Tanax 07-03-2009 11:31 AM

Quote:

Originally Posted by Salathe (Post 26554)
Hehe, fighting. There needs to be two sides to fight, all I'm asking for is clarification on the points he raised. If anything, I'm trying to promote healthier discussion here by asking for more than one-line "this is bad" or "this is what you should do" comments. One might see that as fighting, perhaps, but it's not the intention at all.

I still fail to see why the quoted code should be non-performant and insecure which is why I'm pushing for codefreek's own thoughts. It's not about right and wrong (there probably isn't such a clear distinction anyway) but just about making claims without putting them in context. Why do you think the code would be slowed down, what would you suggest instead? Why do you think the code is insecure, what would you suggest instead?

Ah, I see. Well there are 2 sides. You - Codefreek.
But whatever.

I think he should use sprintf anyways, as I said ^^

Quote:

Originally Posted by sandhyagupta (Post 26558)
I will want to click on any of the postions displayed in my table and then it has to direct me to that page depending on the postion. Hope i am clear this time.

Just echo a link with the positions' ID to a page where it checks which ID is being sent through, and process the data there.

sandhyagupta 07-03-2009 01:57 PM

Thanks everybody for the reply.. my code is working fine as i wanted. But have a small error again. when i click n the first postion it is not taking the jobid. but when i click on the second one then it is taking the first job id and so on.
What exactly is the error.

My code goes this way
PHP Code:

<?php
$nickname 
$_POST['company_nickname'];
include 
'connect_to_databaseemployer.php';

//To fetch all the sub-employer usernames from sub_employer if the company nickname matches
$sql_stmt "SELECT * FROM database name WHERE company_nick='$nickname'";
$result  mysql_query($sql_stmt$conn) or die(mysql_error());
while (
$row mysql_fetch_assoc($result))
{
      
$username =  $row["username"];
      
}

//To check whether the user has any posting.If yes,display the postings sorted by date of posting
$sql_stmt1 "SELECT * FROM database nameWHERE posted_by like '%$nickname%' ORDER BY job_posted_on DESC";
$result1  mysql_query($sql_stmt1$conn) or die(mysql_error());
echo 
"<table border='1' CELLPADDING=5 STYLE='font-size:13px'>";
echo 
"<tr> <th><H3>Posted by</h3></th> <th><H3>Position</H3></th> <th><H3>Job Level</H3></th><th><H3>Posted on</h3></th></tr>";

while (
$row1 mysql_fetch_assoc($result1))
{
      echo 
"<tr><td>";
      echo 
$row1["posted_by"];
      echo 
"</td><td>";
      echo 
'<a href="http://www.konanakunteokkoota.org/applyhereforjob.php?username='.$username.'&jobid='.$postid.'">'.$row1["position"].'</a>';  
      echo 
"</td><td>";
      echo 
$row1["job_level"];
      echo 
"</td><td>";
      echo 
$row1["job_posted_on"];
      echo 
"</td></tr>";
      
$postid $row1["post_id"];
      echo 
"$postid";
}
echo 
"</table>";

?>


Hightower 07-03-2009 02:10 PM

Just a guess as I haven't looked properly but maybe you have to increment your job id i.e.:

PHP Code:

echo "</td><td>";

$postid += 1;

echo 
'<a href="http://www.konanakunteokkoota.org/applyhereforjob.php?username='.$username.'&jobid='.$postid.'">'.$row1["position"].'</a>';  
echo 
"</td><td>"


sandhyagupta 07-03-2009 02:43 PM

Thanks every one. there was a small mistake in the while loop.. now its working fine..
PHP Code:

while ($row1 mysql_fetch_assoc($result1))
{
      echo 
"<tr><td>";
      echo 
$row1["posted_by"];
      echo 
"</td><td>";
      
$postid $row1["post_id"];
      echo 
'<a href="http://www.konanakunteokkoota.org/applyhereforjob.php?username='.$username.'&jobid='.$postid.'">'.$row1["position"].'</a>';  
      echo 
"</td><td>";
      echo 
$row1["job_level"];
      echo 
"</td><td>";
      echo 
$row1["job_posted_on"];
      echo 
"</td></tr>";


I had to just move the $postid before using the url. now its working fine.:-)


All times are GMT. The time now is 05:14 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0