I wonder if anyone could help me with the following please? I have scratched my head and played around but not been able to move forward.
I am creating a script to redirect a user to a random link on my site.
The first part of the code extracts the required fields from the database:
// Select random rows from the database $result = mysql_query ("SELECT A.PID, A.gtitle, A.p1, A.price, B.name, B.seo FROM posts A, categories B WHERE A.category=B.CATID and A.active='1' ORDER BY RAND() LIMIT 1"); // For all the rows that you selected while ($row = mysql_fetch_array($result))
I shuld tidy this code up as p1, price and name are not used - I was reusing another query.
I have then tried to print the result to the screen to check I can construct the url correctly.
I am using the following:
echo "<a href=http://www.mysite.com/\"" . $row["seo"] . $row["PID"] . $row["gtitle"] . "\"> Random Link </a>" ;
This outputting the following link:
whereas it should be:
So that is my first question - how do I get the format correct?
The second is that gtitle is only showing as one word whereas in the database it is more than one. For example 'replace text with buttons' is appearing as 'replace' - I don't understand why this?
In addition for the url I need gtitle rather than looking like 'replace text with buttons' to appear as replace-text-with-buttons' - not sure how to do this.
Finally, once I can construct the url correctly, I want to redirect to that url - the code I was going to use was:
but again not sure how to achieve this or indeed if this is the best way to redirect after pulling a random link.
Sorry for so many questions - I was trying to break it down into logical steps and the echo part was really for testing puposes but was useful to show the problem with gtitle and the fact that I can't construct a URL properly.
Really grateful for any help or advice and thanking you all in advance.