Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Append a variable (from a MySQL query) to a url variable

Codes here !

Moderators: macek, egami, gesf

Append a variable (from a MySQL query) to a url variable

Postby HowardTheDuck » Sat Mar 09, 2013 8:28 am

Hi Guys,
hope this type of question is ok for this forum...

I am customizing a Joomla extension( RSform PRO) and I need to add a variable to a path.
I need to browse a file directory for specific users.
So for example USER1 has files in this folder: /userupload/user1

I have a form that is now able to pickup the "user1" folder name (which is in fact the "user_id"). And I need to "append" this to the path of the uploaded files.

So I need to add "/user1/" to the "/userupload" path.

Any suggestion? What I have been able to do is to just pass my defined variable using this:


//<code>
$my = & JFactory::getUser();
$db = JFactory::getDBO();
if ($my->get('id'))
{
$db->setQuery("SELECT `user_id` FROM `#__briefcasefactory_files` WHERE `user_id`='".$my->get('id')."' LIMIT 1"); // THIS IS THE QUERY TO THE EXTENSION DEALING WITH UPLOADS IN THE USER FOLDER

define("userfolder", "910"); // THIS IS MY "SIMULATION" OF VARIABLE
jimport('joomla.filesystem.folder');

$items = "|Please Select[c]\n";

$files = JFolder::files($RSadapter->config['absolute_path'].'/slideshow/'.userfolder);

$items .= implode("\n",$files);
}
return rtrim($items);

//</code>

the problem is that instead of passing my "userfolder" variable, I should pass the "$db" variable which, after the query is indeed giving me the "folder" name of the user.

Sorry, as you already figured out....I am not a PHP programmer so I guess I am writing silly things!

Thanks
Cristiano
HowardTheDuck
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sat Mar 09, 2013 8:06 am

Re: Append a variable (from a MySQL query) to a url variable

Postby johnj » Thu Mar 14, 2013 5:05 am

After $db->setQuery(), you need to run the query and get the user id to a variable and use that variable.
For example, it could be something like this:
Code: Select all
$sqlQuery = "SELECT `user_id` FROM `#__briefcasefactory_files` WHERE `user_id`='".$my->get('id')."' LIMIT 1"";
$myResult = mysql_query($sqlQuery);

$resObj = mysql_fetch_object($myResult);
$user_id_variable = $resObj->user_id;


I have not tested the above code, but with a few teaks it should work.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Append a variable (from a MySQL query) to a url variable

Postby johnj » Thu Mar 14, 2013 5:07 am

If you need an example of getting data from a table then please take a look at this example:
http://phillipnb.wordpress.com/2010/12/ ... -resource/
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Append a variable (from a MySQL query) to a url variable

Postby HowardTheDuck » Thu Mar 14, 2013 9:52 am

Hi,
thank you very much for your valuable help. I will try this, I think I understood.
Thanks again!
Cristiano
HowardTheDuck
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sat Mar 09, 2013 8:06 am


Return to mySQL & php coding

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron