0

Hello,
I want to combine all my database table in to one line so i can put it all in the url e.g.

Name | Times
__________________________
test1 | 1
__________________________
test2 | 2
__________________________

This is how i want it to look in the url (Result.php?loggedin=true&links=test1-1_newline_test2-2)(newline means that will be a break point when the other page receives is links)

NOTE: After the script retreves the data i'm using header('Location: page') to send the data to the result.php page.

3
Contributors
2
Replies
10
Views
5 Years
Discussion Span
Last Post by jstfsklh211
1

I'm assuming that you are querying your database and looping through the recordset with a while() loop. Within your while() loop, you wanna start building a string, which will be your final URL. So you should start with something like this:

    $link = mysql_connect(/*arguments here*/);

    $query = sprintf("select * from table");

    $result = mysql_query($query, $link);

    $final_url = "http://www.mysite.com/result.php?loggedin=true&links=";

    if ($result) {
      while($row = mysql_fetch_array($result)) {
        // do something with the $row
      }

    }
    else {
      echo mysql_error();
    }

So you have the beginning of your url, as $final_url, and then you just start concatenating the table values to it, with your _newline_ string added at the end of the loop. So I think you'll wanna end up with something like this:

    $link = mysql_connect(/*arguments here*/);

    $query = sprintf("select * from table");

    $result = mysql_query($query, $link);

    $final_url = "http://www.mysite.com/result.php?loggedin=true&links=";

    if ($result) {
      while($row = mysql_fetch_array($result)) {
        $final_url .= $row['Name'] . "-" . $row['Times'];
        $final_url .= "_newline_";
      }

    }
    else {
      echo mysql_error();
    }

    header("Location: $final_url");

_newline_ will print after the last record in the URL, but that can be fixed, or left there, I don't think it's too big of a deal.

In theory, this should work, I hope :)

Votes + Comments
Thank you so much for the help.
0

How large a result set are you likely to end up with?
It might be a better idea to store your data in a cookie or session
instead of writing out and then parsing long strings try using serialize and unserialize to pass your array around

create array from db then
$_SESSION["links"] = serialze($array);
redirect to display page then retrieve
$links = unserialize($_SESSION["links"])

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.