Re: Best solution for creating variables from mysql statements

From: Date: Mon, 07 Jun 2004 18:33:03 +0000
Subject: Re: Best solution for creating variables from mysql statements
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-187824@lists.php.net to get a copy of this message
Nunners wrote:
I'm creating an application which has multiple users, with their own logins etc etc. From it, they have a number of links to external websites, to which I need to pass certain details, e.g. http://somewebsite.com/index.php?username=bob <http://somewebsite.com/index.php?username=bob&password=fred> &password=fred For management purposes, I am wanting to have the overall URL in a MySQL table, and want to be able to use that to get the appropriate variables from another table. So I have: Table: Websites ID Name Website 1 Somewebsite http://somewebsite.com/index.php?username=$username <http://somewebsite.com/index.php?username=$username&password=$password> &password=$password 2 Anotherwebsite http://anotherwebsite.net/login.php?agent=$agent 3 Agreatwebsite http://agreatwebsite.com/index.php?user=$user <http://agreatwebsite.com/index.php?user=$user&id=$id> &id=$id Table: User_Website_Details User Website_ID Variable Value Bob 1 Username Bob Bob 1 Password Fred James 2 Agent 03658264 Greg 3 User Bob_fred Greg 3 Id 49y5h9-845yf9 How can I get the values from the user's individual details into the required output? Cheers Nunners
If you're set on doing it that way, you can set those variables, then do: $url = eval('return "'.$urlFromDb.'";'); but that's icky and a possible security hole. I would suggest removing the query string (variables and values) from the URL you store and just looking through the User_Website_Details for the URL. while($user_web_det = ...) { $url .= $user_web_det['Variable'].'='.$user_web_det['Value'].'&'; } Since you're storing the variables uppser-cased (why?) you may have to do strtyolower on the variable field. -- paperCrane <Justin Patrin>

« previous php.general (#187824) next »