Jump to content

[SOLVED] dynamic data in an array


intodesi

Recommended Posts

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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :P i take what I can get..

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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');

        }

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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')

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

ok I am a moron :P

 

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.