2

My program includes creating hyperlinks for each row in a MySQL table. So I used the C MYSQL API to retrieve the contents of the table:

while ((row = mysql_fetch_row(result)))
  {
....//some code to print the data....
  }

I can output the data. But we need to create hyperlinks in each of the printed results and it should link to another page where I can use that certain string for other processing:

<a href="processfile">text1</a>
<a href="processfile">text2</a>

The problem is: I need to display the string the user clicked in another page. But how would I know what string the user clicked since they are pointing to the same file?

Jared Sohn
  • 443
  • 5
  • 17

2 Answers2

0

You should include extra information within the links that would allow you to look it up within your table.

For example:

<a href="processfile?param=text1">text1</a>
<a href="processfile?param=text2">text2</a>

If the text isn't guaranteed to be unique, perhaps include the row ID there instead.

You can read these extra parameters via

Get escaped URL parameter

if you want to process it clientside or via reading the GET parameters in some other way depending on what you are using server-side.

Community
  • 1
  • 1
Jared Sohn
  • 443
  • 5
  • 17
  • How would I then retrieve the name `text1` in another c cgi script? –  Aug 27 '13 at 03:07
  • That's really a different question. Either search Stackoverflow for how to read GET parameters with C CGI or create a new question for this. – Jared Sohn Aug 27 '13 at 03:10
  • is the name `param` in `param=text1` arbitrarily chosen? –  Aug 27 '13 at 03:13
  • Yes. You could have multiple parameters if you wanted to (i.e. ?foo=1&bar=2) and then on the other side you can read in the values for foo and bar. (But use a library for that rather than trying to parse the string yourself.) – Jared Sohn Aug 27 '13 at 03:15
  • I want to but we're not allowed to use a library. But I can parse it using `strtok`. –  Aug 27 '13 at 03:17
  • If you don't use a library, there are special cases you have to deal with (such as escaping characters). Since you cannot use a library (sounds like a class project), just make sure you test it well for the inputs you expect. – Jared Sohn Aug 27 '13 at 03:23
  • Yes, thanks for pointing that out. I already know to deal with simple key-value pairs like that. –  Aug 27 '13 at 03:27
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/36293/discussion-between-jared-sohn-and-jkta) – Jared Sohn Aug 27 '13 at 04:44
0

You can use get function there

like..,

<a href="processfile/?str=text1">text1</a>
<a href="processfile/?str=text2">text2</a>

and you can get the string in your another page using,

<?php

    $string = $_GET['str']
    //do your process

?>
Anto
  • 610
  • 5
  • 13