intodesi Posted April 21, 2008 Share Posted April 21, 2008 Is it possible to stick dynamic data in an array, like array $pass=array('web','services','print','pricing','other','main','host','grx','contact', 'referrals','links','clientarea','pricewatch','register','login','intodesi','sessions','submit_job','register','reg_form','activate'); what i want to do require 'conf_session.php'; $sql = mysql_query("SELECT client_url FROM clients "."WHERE activated='1'"); while($row = mysql_fetch_array($sql)){ $client_url = '$row', } $pass=array('web','services','print','pricing','other','main','host','grx','contact', 'referrals','links','clientarea','pricewatch','register','login','$client_url','sessions','submit_job','register','reg_form','activate'); Is that even a remotely possible scenario? and if not, how could i get the desired results? Intodesi Quote Link to comment https://forums.phpfreaks.com/topic/102199-solved-dynamic-data-in-an-array/ Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 What exactly do you mean by dynamic data? You want the data pulled from MySQL put into an array? It depends how many rows you have returning. EDIT: Before I get chastised: Yes, I know you can do it with more than one row by putting in a multi-dimensional array, thanks. It gets complicated then, though. Quote Link to comment https://forums.phpfreaks.com/topic/102199-solved-dynamic-data-in-an-array/#findComment-523134 Share on other sites More sharing options...
intodesi Posted April 21, 2008 Author Share Posted April 21, 2008 Well it would only be one row ( i believe thats the right term) i just want to take the client urls from the database and insert them into the array, so every time a new client registers, I don't have to manually add them to my array that checks and makes the index.php?c="whatever" is an allowed url. EDIT hehe well i wont chastise you , I am just looking for advice/code help i take what I can get.. Quote Link to comment https://forums.phpfreaks.com/topic/102199-solved-dynamic-data-in-an-array/#findComment-523139 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 That'd work then...But you seem to be writing over $client_url every time you go through the WHILE loop then. Can you maybe elaborate on what you're trying to do, and I can write something up to help you? And I didn't think YOU'D chastise me, but there's always that person who would be like "Actually, blah blah blah", even though I completely know what I'm talking about. Quote Link to comment https://forums.phpfreaks.com/topic/102199-solved-dynamic-data-in-an-array/#findComment-523144 Share on other sites More sharing options...
intodesi Posted April 21, 2008 Author Share Posted April 21, 2008 Well this is the script that the array resides in, so in the array is a list of allowed pages that $_GET['p' or 'c'] will open if the page is not in the array, then the script will not open the page. I found this code someplace, and did some work on it, with help from this forum, so that its secure from malicious users (as secure as I can figure out how to get it) So I think thats the jist,, $dir = array('/clients/','/clients/clients/','/clients/includes/'); $pass = array('web','services','print','pricing','other','main','host','grx','contact','referrals','links','clientarea','pricewatch','register','login','intodesi','sessions','submit_job','register','reg_form','activate'); if (in_array($_GET['p'], $pass)) { include ($_SERVER['DOCUMENT_ROOT'] . '/pages/' . $_GET['p'] . '.php'); } elseif (in_array($_GET['c'], $pass)) { foreach ($dir as $val) { $file = $_SERVER['DOCUMENT_ROOT'] . $val . $_GET['c'] .'.php'; if (file_exists($file)) { include($file); break; } } } else { include ($_SERVER['DOCUMENT_ROOT'] .'/pages'. '/main.php'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/102199-solved-dynamic-data-in-an-array/#findComment-523151 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 Well this is the script that the array resides in, so in the array is a list of allowed pages that $_GET['p' or 'c'] will open if the page is not in the array, then the script will not open the page. I found this code someplace, and did some work on it, with help from this forum, so that its secure from malicious users (as secure as I can figure out how to get it) So I think thats the jist,, $dir = array('/clients/','/clients/clients/','/clients/includes/'); $pass = array('web','services','print','pricing','other','main','host','grx','contact','referrals','links','clientarea','pricewatch','register','login','intodesi','sessions','submit_job','register','reg_form','activate'); if (in_array($_GET['p'], $pass)) { include ($_SERVER['DOCUMENT_ROOT'] . '/pages/' . $_GET['p'] . '.php'); } elseif (in_array($_GET['c'], $pass)) { foreach ($dir as $val) { $file = $_SERVER['DOCUMENT_ROOT'] . $val . $_GET['c'] .'.php'; if (file_exists($file)) { include($file); break; } } } else { include ($_SERVER['DOCUMENT_ROOT'] .'/pages'. '/main.php'); } ?> Oh, I get it...sort of. >_> Anyway, if you're pulling ONE row, this'll work: require 'conf_session.php'; $sql = mysql_query("SELECT client_url FROM clients "."WHERE activated='1'"); $row = mysql_fetch_array($sql) $client_url = $row; $pass=array('web','services','print','pricing','other','main','host','grx','contact', 'referrals','links','clientarea','pricewatch','register','login',$client_url,'sessions','submit_job','register','reg_form','activate'); Notice: 1) No '' around $client_url in the array. 2) You don't need a while loop for one row. 3) You need to have some way to pull only ONE record. That SQL statement will pull EVERY activated account. You need to use a primary key like a client_id or something. Quote Link to comment https://forums.phpfreaks.com/topic/102199-solved-dynamic-data-in-an-array/#findComment-523157 Share on other sites More sharing options...
intodesi Posted April 21, 2008 Author Share Posted April 21, 2008 well i would need to pull all the records.. i think, well say i have client a with client url index.php?c=client_a and then client b with url index.php?c=client_b i would need to be able to pull both clients urls and stick them in my $pass array or if i had 3 or even 100 clients, I would need all 100 clients to be stuck in that array. I am just confusing myself so $pass would be written like $pass = array('$client_url') and would read $pass = array('client_a', 'client_b', 'etc', 'so_on') Quote Link to comment https://forums.phpfreaks.com/topic/102199-solved-dynamic-data-in-an-array/#findComment-523167 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 well i would need to pull all the records.. i think, well say i have client a with client url index.php?c=client_a and then client b with url index.php?c=client_b i would need to be able to pull both clients urls and stick them in my $pass array or if i had 3 or even 100 clients, I would need all 100 clients to be stuck in that array. I am just confusing myself so $pass would be written like $pass = array('$client_url') and would read $pass = array('client_a', 'client_b', 'etc', 'so_on') Don't use quotes when assigning a variable to an array. I hate to do this, because I really want to help you, but you seem to be a bit confused with what you want to do. Arrays Read up on it and try to figure out what you need. Post back if you still can't figure it out. Quote Link to comment https://forums.phpfreaks.com/topic/102199-solved-dynamic-data-in-an-array/#findComment-523172 Share on other sites More sharing options...
intodesi Posted April 21, 2008 Author Share Posted April 21, 2008 Ok so what I have A database that has client information (name address and the url of their page on my site) what i would like to do take all the records get the client url's from those records and stick the client url in an array of allowed pages so that the page will open. elseif (in_array($_GET['c'], $pass)) { foreach ($dir as $val) { $file = $_SERVER['DOCUMENT_ROOT'] . $val . $_GET['c'] .'.php'; if (file_exists($file)) { include($file); break; } } } and DarkWater I took a look at the link for Arrays, and I am bewildered by it hehe. but looking at some of the array functions, could I use combine() to put two arrays together and write my variable in an array of its own? Quote Link to comment https://forums.phpfreaks.com/topic/102199-solved-dynamic-data-in-an-array/#findComment-523281 Share on other sites More sharing options...
doni49 Posted April 21, 2008 Share Posted April 21, 2008 Here's a brief explanation of arrays from a recent thread. http://www.phpfreaks.com/forums/index.php/topic,191207.msg858491.html#msg858491 Quote Link to comment https://forums.phpfreaks.com/topic/102199-solved-dynamic-data-in-an-array/#findComment-523285 Share on other sites More sharing options...
intodesi Posted April 21, 2008 Author Share Posted April 21, 2008 so would this work? $client_url[] = "$row[client_url]"; Quote Link to comment https://forums.phpfreaks.com/topic/102199-solved-dynamic-data-in-an-array/#findComment-523293 Share on other sites More sharing options...
intodesi Posted April 21, 2008 Author Share Posted April 21, 2008 ok I am a moron I was trying to do the wrong thing.. it wasnt client_url i was trying to insert into the array it was u_name... all client pages are based off their user names, thus that is the variable that needs to be inserted into the array.... so DarkWater Thank you very much.. you solved my problem with require 'conf_session.php'; $sql = mysql_query("SELECT client_url FROM clients "."WHERE activated='1'"); $row = mysql_fetch_array($sql) $client_url = $row; $pass=array('web','services','print','pricing','other','main','host','grx','contact', 'referrals','links','clientarea','pricewatch','register','login',$client_url,'sessions','submit_job','register','reg_form','activate'); I just had to replace client_url with u_name and then i took out the $client_url =$row and in my array just added $row[u_name] without the single quotes as you informed me... and it works.. i beleive.. but only one user is in the database.. so will test again, with two users... Thank you again. Travis Quote Link to comment https://forums.phpfreaks.com/topic/102199-solved-dynamic-data-in-an-array/#findComment-523317 Share on other sites More sharing options...
intodesi Posted April 21, 2008 Author Share Posted April 21, 2008 Ok multiple clients work as far as I can see.. Again, Thank you very much DarkWater Quote Link to comment https://forums.phpfreaks.com/topic/102199-solved-dynamic-data-in-an-array/#findComment-523322 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.