 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
07-02-2009, 02:28 PM
|
#1 (permalink)
|
|
The Wanderer
Join Date: Jun 2009
Posts: 20
Thanks: 4
|
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.
|
|
|
|
07-02-2009, 03:01 PM
|
#2 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
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?
|
|
|
|
07-02-2009, 03:02 PM
|
#3 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
Thread moved to:
Absolute Beginners
|
|
|
|
07-02-2009, 03:02 PM
|
#4 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
Quote:
Originally Posted by codefreek
Thread moved to:
Absolute Beginners
|
Haha, that would explain why it wouldn't let me do it.
|
|
|
|
07-02-2009, 03:06 PM
|
#5 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
@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.
|
|
|
|
07-02-2009, 04:13 PM
|
#6 (permalink)
|
|
The Addict
Join Date: Aug 2008
Posts: 336
Thanks: 8
|
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.
|
|
|
|
07-02-2009, 09:17 PM
|
#7 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
Quote:
Originally Posted by tony
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
Last edited by codefreek : 07-02-2009 at 09:36 PM.
Reason: added more explaining
|
|
|
|
07-02-2009, 09:21 PM
|
#8 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
Quote:
Originally Posted by codefreek
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.
|
|
|
|
07-02-2009, 09:34 PM
|
#9 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
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)
|
|
|
|
07-02-2009, 10:24 PM
|
#10 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
You make two claims.
- 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?
- 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?
|
|
|
|
07-02-2009, 10:42 PM
|
#11 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
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).
__________________
|
|
|
|
07-03-2009, 10:13 AM
|
#12 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
Quote:
Originally Posted by Tanax
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?
|
|
|
|
07-03-2009, 11:14 AM
|
#13 (permalink)
|
|
The Wanderer
Join Date: Jun 2009
Posts: 20
Thanks: 4
|
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.
|
|
|
|
07-03-2009, 11:31 AM
|
#14 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Quote:
Originally Posted by Salathe
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
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.
__________________
|
|
|
|
07-03-2009, 01:57 PM
|
#15 (permalink)
|
|
The Wanderer
Join Date: Jun 2009
Posts: 20
Thanks: 4
|
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>";
?>
|
|
|
|
07-02-2009, 10:44 PM
|
#16 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
on nr 2 on your list/question, i would say at least use sprintf..
|
|
|
|
07-02-2009, 11:42 PM
|
#17 (permalink)
|
|
The Contributor
Join Date: May 2009
Location: LA, CA
Posts: 87
Thanks: 0
|
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.
|
|
|
|
07-03-2009, 02:10 PM
|
#18 (permalink)
|
|
The Acquainted
Join Date: May 2009
Location: Durham, UK
Posts: 134
Thanks: 9
|
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>";
|
|
|
07-03-2009, 02:43 PM
|
#19 (permalink)
|
|
The Wanderer
Join Date: Jun 2009
Posts: 20
Thanks: 4
|
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. 
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|