Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Dynamic Variables In Php?


Hi,
I have a mySQL table that contains two columns
column one is 'feature' and column two is 'feature_value' - some of the data is for example

'hair_color' - 'blue'
'hair_color' - 'blonde'
'hair_color' - 'black'
'hair_color' - 'gray'

'eye_color' - 'blue'
'eye_color' - 'hazel'
'eye_color' - 'brown'

Yeah I know... definitely NOT third normal form. OK here's where it gets even better

On one web page, I build select controls from this data. The name of the control would be the value of the feature column. So from the data above I would have a select control whose name would be name="hair_color" and another select name="eye_color"

NO problems so far.... ok.
Now after the user selects from the selects (get it, sorry).... i am processing the data.

Although I use javascript for some client side validation... I also want to validate in php. (ok, just because I want to ok)

NOW.. the web page form will post these two variables $hair_color' and '$eye_color' as described above. But I don't know ahead of time what these variables are because they're based on data from a table.......

I go the table described above and select distinct on the feature column - I will return two rows.... see below

while($row = mysql_fetch_row($result_set)) {
$feature =trim($row[0]);
}

the value of feature in the first row is 'hair_color' and in the second row 'eye_color'--


What I'd like to do.... is to take the values in the $feature variable and create a literal variable that I can test for that was posted from the form........

so for example in the first row where $feature = 'hair_color' - I want to create a $hair_color variable...... because this is a variable of the select control from the form. Then for the second row where $feature = 'eye_color' - I want to create an $eye_color variable because again... this is the variable of a select control on the form.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Dynamic Variables
I am NEWBIE & trying to develop internal control system with PHP-MySql & have one problem.

I want to enter dynamic variable into MySql like :

"I have checked report of Mr. $userName from $previousDate to $currentDate…..”

Wherein - $username, $previousDate, $currentDate will be called from other table.

My codes :

PHP Code:

INSERT INTO `checkReport ` (`schID`, `schNo`, `noteNo`, `subschName`, `content`) VALUES (1, 1, 'a', '', ' I have checked report of Mr. ‘.$username.’ from ‘.$previousDate.’ to ‘.$currentDate.’ ….)

which is not working… Please guide me through.

Dynamic Variables
I know there's a way to have variables be created dynamically. What I'm trying to do is to pass information about products to PayPal, but I don't know how many products are going to be in each cart.  It could be 1 or 100. I need to create a variable who's ending number changes depending on how many products are in the cart. How do you have those created dynamically?  I need the information to be passed through hidden variables via an HTML form as well.

Dynamic Variables Within A LOOP
Ok, problem, running through this loop to upload a thumb and large image of origonal one provided, and to generate names for the database for each upload.

The problem is it wont assign the name for the second and third itteration properly, instead of being the VALUE its the name of the DYNAMIC VARIABLE, all files are uploaded correctly, all other entries in the database are fine including the first picture name, it just fails to work on the last two loops of the for statement.

CODE (Sorry for the mess) :

Creating Dynamic Variables
I'm trying to pass 100 variables (named gain1, gain2...gain100) from a swf to a php file then write these variables to a text file.  Sending the data works fine. 

I just need help creating the variables in the php file.  Since all the files have partly the same name, I was hoping to create the variables dynamically.  I was hoping to do something like this:

$myFileName = "myfile.txt";
$myFileHandle = fopen($myFileName, 'a') or die("can't open file");

for (i=1; i<100; i++) {
$gaintext + i= $_POST['gaintxt1' + i];
fwrite($myFileHandle, $gain + i);}

However, this isn't working obviously. 

Dynamic Declaration Of Class Variables?
I have a mysql table, but because there are lots of fields, I want to create automatically variables in the class, taking their names from fields' names.

I know how to do it outside a class, but in a class you have to declare the variables before use them. So I can't figure out how to dynamic declare variables through code inside the class. Any idea? Or is it possible?

How To Get A Dynamic Javacript Form Variables Seperated In PHP
PROBLEM: I have this form that allows the user to dynamically create
additional fields (see javascript code bellow). I am trying to retrieve
the values entered into these fields from my php script. I ultimatly
need to pick out the variables and place the values into my php script
page. I have worked with a little code I found on php.net (see php code
below), but I wan unable to grasp the knowledge on how to seperate the
variables in the address bar. Please reply.

QUESTION: How do I create variables in my php script from my dynamic
javascript form?

PHP CODE:
foreach($_GET as $name => $value) {
print "$name : $value<br>";
}

JAVASCRIPT CODE:
<HEAD>
<!-- Begin
function createForm(number) {
data = "";
inter = "'";
if (number < 16 && number > -1) {
for (i=1; i <= number; i++) {
if (i < 10) spaces=" ";
else spaces=" ";
data = data + "URL " + i + " :" + spaces
+ "<input type='text' size=10 name=" + inter
+ "url" + i + inter + "'><br>";
}
if (document.layers) {
document.layers.cust.document.write(data);
document.layers.cust.document.close();
}
else {
if (document.all) {
cust.innerHTML = data;
}
}
}
else {
window.alert("Please select up to 15 entries.");
}
}

Same Named Variables.. Or Addressing Variables In A Loop
I'm just starting to program in PHP.. fairly new to programming in general... and I've run across a (probably simple) programming problem I hope someone can help me with. I'm sending variable names through an HTTP get that are generated through a foreach loop. The names are along the lines of name1=, begin1=, end1=, name2=, begin2=, end2=.. etc. The number is the number of the current cycle through the loop. My problem is addressing the variables on the next page... namely how do I evaluate those variables in a loop? I want the value of name1.. but obviously

for (i=1; i<3; i++)
{
echo "$name$i";
};

is not working. Is there an easy way to do this?

Passing Variables & Dummy Variables
Hi! thanks for all the previous help - I've made some progress & have dropdowns and a checkbox; however I have 2 probs which I can't figure out: grateful for any further help. THANKS!

1. Not sure how to code so that user can query from just 1 or all of the dropdowns (at the moment unless they select the correct answers from each dropdown - no results!) = defeats the whole purpose of searching. By selecting from menu options user selects from 2 diff tables.

[the page allows user to search catalogue by selecting year of release, artist, music type - results from 2 tables need to be selected & sent to mysql.

I just don't know how to code it so that user must make an initial selection to get any results, and whichever menu options they choose "add them together" if you like to make a complete query.... sorry my coding just isnt deep enough!

A friend suggested using a dummy variable but as I'm a bit out of my depth; I need to get some help!

The coding I've done so far;

Passing Variables And Session Variables
I'm currently working on a shopping cart script that works just fine with register_globals turned on but when turned off i get all kind of errors. The following page displays a detail of the book with the "Add to cart" link at the bottom. PHP Code:

Passing My Variables With Forms Variables
how to carry variables onto the next page along with the forms variables. I need to carry my own over too, but when I press submit on the form page only the forms variables carry over, not my own ?? I have two drop down menues on my form that provide two values "start & end" which I require to go with my own variables.I have tried "a href=" link which carries my variables but not the forms variables.

<?php
echo"<form method=get action=somepage.php?one=$one&two=$two&three=$three&four=$four>";?>
also tried
<a href=somepage.php?one=$one&two=$two&three=$three&four=$four&start=$start&end=$end

Persistant Variables - Application Variables
In the books I have read about PHP I haven't been able to find any descriptions of how to set variables that persist in the servers memory, in the way that Application variables persist in Cold Fusion.

In CF, if I set an application variable then any of the application pages that are run will have access to those variables. And you can put complex arrays of data in the Application Variables and then access these variables at any time, without having to reload those variables for each page when it loads. I expect you can do this is PHP, but I can't find any info about how to do this.

Variables That Change Session Variables
I'm currently writing a mulit-page form app that uses a session to
retain data from each form element in order for the user to jump
between pages, then the final data is passed to a calculation script.

However, I've noticed that if I assign a session variable to another
variable, which then performs a mathematical calculation, the session
variable changes.

i.e. $_SESSION["inflation"] = 4;

$temp_inf = $_SESSION["inflation"];
if ($_SESSION["inflation"] =="RPI") {
$inflation = $rpi;}
else {$inflation = ($temp_inf/100.0);}

now it equals = 0.04

How can I take a value from a session and perform operations on it
without altering the original session value.

Form Variables To Session Variables
I am writing a small script that consists of two pages:  page one displays a bunch of values from a DB (ie. First Name, Last Name, Phone Number).  On this page you will find a form that follows this format:

<input type="text" name="edit_firstname" size="20" maxlength="35" value='Bob'>
<input type="text" name="edit_lastname" size="20" maxlength="35" value='Smith'>
<input type="text" name="edit_phone" size="20" maxlength="35" value='5552222'>

So when you see the page there will already be a 'default' value in each line (which is information extracted from a DB).  This works perfectly and has been tested thoroughly.

On the second page I have the following code:

$editfirstname = $_POST['edit_firstname'];
$editlastname = $_POST['edit_lastname'];
$editphone = $_POST['edit_phone'];

What I am trying to do is this:  the default value for edit_firstname from the form is 'Bob' by default, but the user can change this in the input field on the first page.  This value, whether changed or unchanged, should then be stored as edit_firstname and by calling up the function $_POST[''] on the second page I want to transfer the value to the variable $editfirstname. 

However, it seems that $_POST['edit_firstname'] and the other fields do not return a value at all, hence $editfirstname = '' or $editfirstname = 'NULL'.  I have never tried to do things this way before. 

Building Variables From Variables
I am trying to build a variable, that will have a amount of that
variable, can someone describe/explain in detail the best method to do
this?

Dynamic Nav Bar
I am trying to implement a dynamic navigation bar. My problem is as follows -

All of my scripts are located in various folders, and as you move to different areas of the site, the links to the other areas of the site will change. For example, I am currently at home.php and the nav bar has references to admin/manage_users.php and companies/view_employees.php, etc etc. If I go to manage_users.php, I am now executing a script in the admin folder. The nav bar still has a reference to companies/view_employees.php, which would make this a dead link.

There are lots and lots of directories and subdirectories that one can navigate to, so I don't want to have to write code for a nav bar every time. Is there something like $_SERVER['DOCUMENT_ROOT'] that I can use that will help?

Dynamic Links???
I’ve looked at several tutorials and searched the archives of this site. I found a few pointers, but I feel entirely daft and can’t seem to quite get it.

The “ultimate” goal is to display members profiles, and not have to hard code all the bl**dy records, as I’ve done so far. (Current version http://www.internetbonsaiclub.org/c...y/profiles.html)

So, now I have the records in one table in my database. The profiles.php3 page takes all the records in that table, and displays the names in alphabetical order. So far, so good.

Now, I have viewprofile.php3, which should display only one record at a time, based on which name the visitor clicked on.

Dynamic Menus
how to have dynamic menu, say one option is selected from the first menu, and that option changes the 2nd menu options. ?

yeah i have seen it work in JavaScript, (onchange)
but what would the syntax be in php ?

Dynamic Communication
I am wondering if there is any way to use maybe XML to mimic another sites form on my site. For example, to use maybe Expedia's flight search form on my site and then post the request to expedia and have the results format back into my site. It is sort of the same concept as xml-rpc accept I am wondering if it can be done without setting up an xml-rpc server for the response. Essentially the script would allow you to take the user through the entire search process all the while making it formatted to the layout of your site, but using Expedia's engine.

Dynamic Notification
Is there a way for me to have an email sent to me anytime one of my users creates/uploads a new file in a specific directory on my website? Sorry if this is really basic.... I'm not sure where to start. Any help would be greatly appreciated.

Dynamic Content In A <div>, Using Php
i have a <DIV> block, and I want the innerHTML to change at the click of a button. for those who don't know some javascript, if you have a dive with an id, <DIV id="myDiv"></DIV> you can change the content inside with a function call

myDiv.innerHTML = "some stuff";

however, i need my data to come from a mySQL database and thus needs to be outputted via php. so ideally i want something like

myDiv.innerHTML = "<?php echo "some stuff"; ?>";

of course that does not work because php is not client side, this is just to illustrate what i want. any ideas on how to do this without iframes?

Dynamic Data
I have included a php script into my page
as <img src="plot.php">. That script just plot some time changing data. Now I have two questions that I cannot solve myself:

(1) When I press the reload button I expected
the plot reflected the changed data.
Instead of that plot remains unchanged
until I directly invoke the php script
from the browser...
Is there any method to avoid this
unwanted caching?

(2) That is a bit off topic but is there
any easy way to get a web page updating
after a certain period of time?
Once solve my first question I'd like
to offer mi visitors a automatically
changing graphic.

Dynamic Php Tables
As you'll notice, each new result appears in a new table, which is very annoying. I am trying to make it so that all ther results appear in 1 table.

This is what I have so far;

<?
//error message (not found message)
$XX = "No Record Found";
$query = mysql_query("SELECT * FROM $usertable WHERE $metode LIKE '%$search%' LIMIT 0, 30 ");
while ($row = mysql_fetch_array($query))
{
$variable1=$row["Model"];
$variable2=$row["Creator"];
$variable3=$row["Title"];
print ("$variable1, $variable2 ,$variable3");
}

//below this is the function for no record!!
if (!$variable1)
{
print ("$XX");
}
//end
?>

Can anyone help please?

Dynamic Playlist In XML Using PHP
I want to build a dynamic playlist in XML using PHP.
can any body please help me by giving code,ideas and links?

Dynamic Table
I'm working on creating a dynamic table generator. The data is read from a database via mySQL. The table sample is: Code:

Dynamic Thumbnails
ImageCopyResampleBicubic()

here is a modified version of the above code that will properly handle copying only portions of images (i.e. creating a square thumbnail from a rectangular image by cropping out the square rather than smashing to fit). Also a few breaks were added to avoid some unnecessary calculations that took place under some conditions: PHP Code:

Dynamic Playlist, From URL
I have many complex ASX playlist files and would like to cut my work down managing them by having one line in them dynamicly created on the fly depending on a link the visitor clicks.

Is there a pre made processor that will look in the URL for a variable, insert that variable into a pre made ASX script and return that modified ASX script back to the client?

Dynamic Form
I have one user table in my MySQL database and this is linked to a user type table containing 3 types of user. Each type of user will be required to give a different amount of data when registering.

Basically I want to create one registration form for all types of users but only show the form fields that are relevant to the individual user type. The user type will be selected from a pervious page containing a list menu with the 3 user types that is sent via GET to the registration page.

Dynamic FAQ Software
Can anyone suggest some PHP software for maintaining a FAQs page?

I want to include moderate user contributions, but I don't mind modifying something to get what I want.

(I have tried searching for this but can't seem to come up with a search string that weeds out are the FAQs pages out there)

Dynamic Maps With Php?
I have a little php application to store day hiking trips and to keep a
running total of their yearly trips for a few users. Currently they
select their hiking routes using drop lists or checkboxes containing the
names and numbers of the trails. If the route is simple the form takes
1-2 minutes to fill in, if it involves lots of tiny sections it can
become tedious to search for every trailname and may take 20 minutes.
Because of this they have asked for a map, rather than lists, and want
to open the application to the public. Hmmm..

So I'm looking to create an application where users can select their
routes, by somehow selecting lines on a map, then somehow pass this to a
php script to process.

Dynamic Grid
I'm attempting to make a dynamic grid (3 x 3, so 9 squares total) I'm currently using a table because I don't feel like dealing with some css issues i was having in IE.

Anyway what i have is a 3 x 3 square
(periods used for spacing) ....

Dynamic Array
Say I have a function that is used to open different flat-file databases and read them into arrays. The databases have a different number of field indexes, with different names.

Is there a way of creating an array within a generic function, but with the field indexes as keys instead of just numbers?

Dynamic Arrays
People come to my site, they choose the name of a car from a database. I want the name of the car to go into an array. I want to put it in an array and not just as a single variable because i want them to have the option of coming back to the page and choose the name of another car. They can have as many names of cars as they like. To make sure i retain the values of the array, i will put them in a session variable.

My question is how do i generate the dynamic array? When people come back to the page with the values of the array in the session variable will that cause a problem?

Dynamic Zipping
I'm working on a downloads site at the moment and need to have a sort of dynamic zipping system, i'll explain:

1. A user visits the site, they are given an individual ID

2. They browse through the files and can click on the 'Add to Download' button if they wish.

3. If they click on the 'Get Download' button, then they are sent to a page, which offers them all the files they selected in a .zip or .tar file for downloading.

Dynamic Table
I am trying to create a table dynamically- meaning that a user will be able to add or delete rows via an admin tool. For now, the number of columns will be a fixed number. I figure I can store each row of information in a database and then keep some type of index to keep track of column inserts, deletions, etc. Does this make sense? Does any one have any ideas on how to accomplish this?

Dynamic Pages
I am trying to create a page which will automaticlly change the size of
tables/graphics etc based on the screen resolution. Eg, if someone is using
a 800x600 the page layout will utilise this. If the same webpage is
diaplayed on a 1024x768 or 1280X1024 the cells are adjusted according. By
doing something like this could you make the logo change size by using a
percent size in a table cell or is there a better method than tables? If
anyone is able to help with tips or any examples (code or url reference) it
would be appreciated.

Also, what page layout is better to use.. eg.. html, php,asp, etc. The
site will be hosted on apache on a Linux Server.

Dynamic Menus
<?php
include('./common_db.inc');
$link_id = db_connect();
mysql_select_db("test_db");

?>

<form name=carform action=
<?php echo $_SERVER['PHP_SELF'];
?> method=post>
<?php


$query =mysql_query("select DISTINCT CQ_PROD_PLATFORM AS make_id from
CQ_data ORDER BY make_id");
echo '<select name=make
onchange="document.carform.submit()"'.">"."
";
if (!isset($make))
{
echo '<option value=null selected>Choose a Make</option>'."
";
}
while(list($make_id) = mysql_fetch_row($query))
{
echo '<option value='.$make_id;
if (isset($make)&& $make_id == $make)
{
echo " selected";
}
echo '>'."$make_id".'</option>'."
";
}
echo '</select>'."
";
echo '<select name=model
onchange="document.carform.submit()"'.">"."
";
if (!isset($make))
{
echo '<option value=null selected>Choose a Make First</option>'."
";
}
else
{
$result = mysql_query("select DISTINCT CQ_SUBSYSTEM AS name from
CQ_data where make_id='$make' ORDER BY NAME");
echo '<option value=null selected>Choose a Model</option>'."
";
while(list($model_id) = mysql_fetch_row($result))
{
echo '<option value=' . $model_id;
if ($model_id == $model)
{
echo " selected";
}
echo '>$model_id</option>'."
";
}
} echo '</select>'."
";
?>

Dynamic Links
I would like to create dynamic return paths as links on site pages. For example, there might be a link to the whet stone page on both the chisel and plane pages. If my viewer came from the plane page, I'd like the return path to indicate "home->planes->whet-stones", appropriately linked. Likewise if from the chisel page, "home->chisels->whet-stones".

Above the immediate back link, normal site layout logic would apply. Should the referer page be off site, site layout would rule. This doesn't appear to be particularly difficult.

Dynamic Forms
I would like to know if it is possible to make a dynamic form. I've got to do some reservation forms for car rental agencies. There are about thirty different input possibilities on these forms. eg. some want to have a form that asks for the pickup time, and some want radio buttons that say pickup time is AM or PM. Each company would like about 10 of these to be on their form. If I have a database (MySQL) and can keep each customer preference in there, could I dynamically make a form?

Dynamic Dropdowns
I got a script a while back that populates dropdowns from a database, Im using PHP with this, WHat I want to do with the dropdowns is populate the list boxes depending on a variable that is passed through the URL, I can do it for the countries ok, but it wont load the citys I hope some one can help me out.

Its the javascript Im having the problem with. Heres the script, you will need to run this on a PHP enabl server with a mysql DB. PHP Code:

Dynamic Dropdown?
I am posting a code for dynamic dropdown by Leon Atkinson, it works fine but i have a doubt: I tried to add another functionality to it where i got stuck! Once the city also gets selected from the second drop down i wanted that on clicking the submit button it should go to some html page wrt to the city choice. Code:

Dynamic Charts
Is it possible to create dynamic charts or dynamic excel sheets to show charts and graphs based on values from database and display it on the web using php?

Dynamic Variable
i was wondering how to call a dynamic variable on php Code:

Dynamic Form
I need to create a form that takes a number that the user enters, and
duplicates a question the number of times the user entered. For
instance, if the customer enters 5 on the first page, when they press
next the form generates "How old are you?" 5 times on the page. The
customer will answer all 5 questions then press next. Finally, all the
local variables get dynamically created and written to a database.

I have already taken care of dynamically creating the question five
times. Using a simple WHILE clause, this generates the correct number
of questions. What I am having an issue with at this point, is how to
dynamically create the local variables.For instance, for the question
"How old are you?" I would need a unique variable for each instance;
using something like $Age(n). So that for five times, it would
automatically created variables $Age1 through $Age5. I have carried
over the number to the submit page by creating the variable $Number
and passing it along as hidden button on the form. $Age'$Number'
seemed to work for creating the variable, but $_post["Age'$Number'"]
doesn't work for referencing the global variable. I would need some
way of looping through and dynamically creating the variables.

Dynamic Image?
Who knows how this is done:

As you can see the signature is dynamical, it uses gdlib I assume and php.
But does anybody have any code for this? Please help me find this, I
allready searched alot, but can't seem to find anything yet...

Dynamic Checkboxes
I am doing a structure of booking on line, and now I Have to make this: when anybody books a place (checkbox) it is inserted in the database (column posti) and it must change from a check box to an image PHP Code:

Dynamic Form
I had to make a form for someone, with 42 questions each question had different form-elements. I was typing and coding for almost 3 hours..!! lets say we would make a form (formmaker.php) to dynamicly create a form with multiple questions: on the formmaker :

-first we have to enter the number of questions (max 100)
-then we have to type the question(s) in (an) input field(s)
-then we would have to select a type of answering field (textbox, checkbox, radiobuttons, file, dropdown etc. )

-it would be nice if we could select to make the question mandatory or not.
-if we choose for checkboxes or radiobuttons , it would be nice to know how much of them (no limits here !) ok..limit it to 30

-when we have selected...for example..15 checkboxes, they have to dynamicly appear on the formmaker.
-for each checkbox or radiobutton, we have to enter a value.
-finaly we have to add an email adres to each question !!! (and a BCC field) (this way, we can use one form and split and send the data to multiple recipients..!!)

-also we have to be able to dissable or enable a question. (if dissabled, it wont show on the created form..

A nice template to show a filled in form is preferable.. It would be nice to store everything in a database tabel. (for each new form a new tabel in the database) question1 id active(yes/no) questiontext fieldtype mandatory(yes/no) radio_or_checkboxvalue1(rocv1) rocv2 rocv3 rocv4 rocv5 etc.... sendto_email bcc_email
I started with the code already...here it is: Code:

Dynamic Button
what i have:
a dynamically generated table from a mysql database
a hidden field in each row that is = to the current rows key field

what i need:
since the field NAME is the same with each row it seems that the next page always pulls the last row instead of the one i select, i think i need a way to make each hidden field name to be unique and a way to get that on the next page??

Dynamic Header
i wanna provide information by taking another website active links to my page and each time visitor click the pages they go different pages, but how to insert static header (in the top of new pages of active links) but the active links always change like yahoo did?

Dynamic Tables
I am creating a dymanic website generator in php/mysql and I have a particular question. I have the following sql statement:

$sql = "CREATE TABLE one (
Email CHAR(50) NOT NULL,
First_Name CHAR(25) )";

and it works just fine. I need it to act dynamically and vary with different contents that are being submitted by a form. In short, I need the name of the table that is being created to be a variable and not a static name. Here is an example:

$sql = "CREATE TABLE $wstitle (
Email CHAR(50) NOT NULL,
First_Name CHAR(25) )";

Can this be done in any other way that the above example because it does not work.


Copyright © 2005-08 www.BigResource.com, All rights reserved