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




Creating Queries Dynamically


I've been struggling with a problem for a while and I think that the solution lies in the ability to create queries dynamically. On one page I have a number of drop-down menus created dynamically, so the number of menus can vary. Each drop-down represents a try/touchdown scored, and the user would select from the menu who scored it. On the next page I want to take the info entered and send it to the database, automatically creating new entries for each try/touchdown scored. Code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Dynamically Generate MySQL Queries
what I expect will be a
reasonably simple question.

I have an html form (which is generated in php) which contains a
number of rows (one row per product in the 'products' table).

It is generated with the following php

<code>
// create a table for the results
echo('<table border=1 cellpadding=2>');
echo('<tr> <th>Product Description</th><th>Sales $</th><th>Sales
Units</th><th>Credits $</th><th>Credits Units</th> </tr>');

// add the results to the table
while ( $row = mysql_fetch_array($result) ) {
// get columns from the output on the current row
$ProdDesc = $row['ProductDescription'];
$ProdID = $row['ID'];
// write content collected above into table cells
echo('<tr><td>');
echo($ProdDesc);
echo('</td><td>');
echo('<form action="update-db.php" method="post"><input type="text"
name="sd');
echo($ProdID);
echo('">');
echo('</td><td>');
echo('<form action="update-db.php" method="post"><input type="text"
name="su');
echo($ProdID);
echo('">');
echo('</td><td>');
echo('<form action="update-db.php" method="post"><input type="text"
name="cd');
echo($ProdID);
echo('">');
echo('</td><td>');
echo('<form action="update-db.php" method="post"><input type="text"
name="cu');
echo($ProdID);
echo('">');
echo('</td></tr>');
}
echo('</table>');
//the table is complete
</code>

The values sd1, su1, cd1, cu1,...... cuXX are all available to the
update-db.php page which is called when this form is submitted so I am
fairly sure this is working correctly.

So far, so good, but when it comes to inserting the data into the
database I have not been able to create the SQL dynamically (in
testing I know the number of products and have manually written lots
of SQL INSERTs but this will not work in the real world)

The SQL needs to look like roughly like this:
mysql_query ("INSERT INTO sales_dollars (SaleID, ProductID,
WeekCommencing, Sales, Credits) VALUES ('',
'$prodID','$WeekCommencing','$sd1', '$cd1')");

My logic was to say something like this (which needless to say doesn't
work !)
<?php

for ($prodID = 1; $prodID <= $prodCount; $prodID++)
{
$currentSD = "sd" . $prodID
$currentSU = "su" . $prodID
$currentCD = "cd" . $prodID
$currentCU = "cu" . $prodID

mysql_query ("INSERT INTO sales_dollars (SaleID, ProductID,
WeekCommencing, Sales, Credits) VALUES ('',
'$prodID','$WeekCommencing','$currentSD', '$currentCD')");
}

I may have messed up the for loop here but the real problem was that
query would insert '$sd1', '$sd2' etc as text strings into the
database rather than evaluating $sd1 to it's value (passed from the
original table which would be a number)

I have tried using eval() with no success (though that may well be due
to my complete newbieness with php). I have also tried passing the
values from the original html as arrays and trying to use simillar
logic as above to read from $array[$currentArrayElement] also with no
success. Again, if I manually echo the results of $array[0] I am
returned the value entered in the first html field but I can not
dynamically select the next array element.

I hope I have made sense of the problem without writing unnecessary
garbage.

Dynamically Creating A Crontab
Is it possibe to dynamically create a crontab. Say i have a form to enter minute, hour, day, etc... and wanted to create a cronjob that ran to those values. Has anyone done this?

Creating .m3u Files Dynamically
Im looking at creating a playlist program for my server.  i have alist of files within my database, and i wanted to be able to place these values into a playlist file.  the problem is that i dont know how to get the database to create the playlist form its records.  ie, if i uploaded a new file to my server and into the database, then i woudl want the script to automatically grab that file ( SQL  i know), anbd the nplace it in the m3u file ( i dont know).

Coudl someone recommend a simple method to complete this?  or point me in teh righ t doirection for a tutorial?

Dynamically Creating An Image With Imagecreate()
I have a multitude of images that I am trying to bring up dynamically depending on the scenario. These images are different sizes.
To complicare things just a little more, I am rewriting a javaScript. Am I heading into the correct direction?

Here is the original JS that I am attempting to rewrite: (This is most of the way translated to PHP)

Creating Update SQL Queries
Anyone out there know of a good way to dynamically create an UPDATE statement such as:

<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
$query_upd = "UPDATE $table SET $values WHERE custid='$custid'";
[/code]

$values would be something like field1='$field1',field2='$field2', and so on.

Code prior to this reads the DB structure and gets the table field names. Then I want to be able to update the values. I've experienced a problem dynamically creating this though because of some problem related to magic quotes I haven't been able to solve.

If you have a good way of dynamically creating the queries and would like to share.

Dynamically Creating URLS Based On User Input !
I am looking to create pages on the fly or dynamically based on user input. For example if i have www.example.com and they visit this and enter 'bob' in a textfield and press submit they create www.example.com/bob.html . How would I go about this ? I am guessing I need to create a folder when submit is pressed in my website directory ?

Dynamically Populate Drop-down List And Dynamically Include Html File
We have a drop down list on a PHP page, with several product names, and
when people click one item, we will refresh the same page with the
product name as parameter, and in turn we want to include a HTML file
into the content area of the same page.

I know it is recommended to put everything into database, but we want
the web site to be very "portable", so the drop-downlist and the
content should both in text files.

Let's say the drop-down list will be poplulated from the product.txt
file, and there will be a file for each corresponding item in the
drop-down list. From the user point of view, if he wants to add a new
product, he will just need to open the product.txt file, and add a new
line with the product name, "Laptop", then add a new text file named
"laptop" in the same folder which contains the HTML fragment to be
included in the content area.

What is the easiest way to do this?

PostgreSQL Queries, Storing Results Instead Of Multiple Queries
I have a script that does multiple SQL queries.

So I have something like $result = pg_query($my_query);

After this query I tend to loop through like this to get the result:

while ($entry=pg_fetch_row($result))
{
 //do stuff
}

But my question is, how can I make a copy of the result? So I don't run the query more than once.

How To Dynamically Name Variables?
Lets say I have variables named: name1, name2, name3, and name4. How can I call them without having to name them everytime. Something like

for ($i=1; $i<=20; $i++){
if $"name".$i {
do this }

I've tried everycombination I can think of, but am totally confused. I had no trouble naming the variables dynamically in a form, but I can't get php to call them dynamically.

PHP To Dynamically Generate XML
I am interesting in using PHP to dynamically create an XML document and
then use XSLT to transform to XHTML. I have come across two methods for
doing this. I made two equivalent examples so you can see what I mean.

http://members.shaw.ca/petermichaux...SLT_method.html

I am interested in critisim of how I implemented each method. However
my main problem is deciding between methods. Which method is better for
bigger programs where the bits of the XML data are assembled by various
php functions that I write?

For example, one php function queries a database table for a list of CD
titles. A second php function loops through this CD title list and gets
the track listing for each CD from another table in the database. Then
the composite XML data (ie. CD title and tracks as nodes) can be
tranformed to XHTML.

Dynamically Naming Variables
i have this script for that uses 7 pulldowns for the time of an event each day of the week that gets inserted in to a db. Instead of writing the script 7 times for taking the data from the pulldowns, creating a time based on the hour, minute and AM/PM -can i create something that dynamically creates varibles. Basically takes something like $hour1, $minute1 and automatically creates $hour2, $minute2 and so on. This is kinda difficult to explain, heres a snippit of code which i want to duplicate.

Dynamically Incrementing Arrays
I tried searching for this, but couldn't find exactly what I wanted.

Dynamically Resizing An Image
I want to create a thumbnail image. But I don't want to physically resize each
image before uploading it (actually, my client doesn't really have the capability).

Can I dictate a height (i.e. 108 px) and have a PHP script that will
proportionately size down the image using that height? So, if the original is 360 px wide by 540 px high, the image will automatically size to 108 px high by 72 px wide.

How would I do this?

Dynamically Generate Mp3 Clip
I have page in which user will upload song and i need to automatically
generate a 30 second clip of the uploaded mp3 file and save it

can anyone suggest how to do this on linux server which software to use

is it possible with ffmepg or ffmpeg-php to cut a 30 second clip or 60 second clip etc.

if you have any example then please show me how to do that.

Find Domain Name Dynamically
I have 2 registered domains, which point to the same web root folder.
I would like to display a different logo image depending on which domain the user requested. Is it possible to find the domain name with PHP?

How To Change Data Dynamically ...
I'm developing a system where user has a previlage to select
his/her COUNTRY then STATE then CITY respectively. i've put all the
Country names, State names and City name in a Drop-Down combos which
is filled dynamically from the MySQL database. Now my problem is that
i want it in such a way that if one select USA as COUNTRY then all the
STATE(s) of USA should be displayed on the STATE combo not any other.
and then when user selects the STATE in the next combo the CITY combo
should be populated with cities related to that STATE only and not
with any other.

Dynamically Generate Mp3 Clip
I have page in which user will upload song and i need to automatically generate a 30 second clip of the uploaded mp3 file and save it. can anyone suggest how to do this on linux server which software to use? is it possible with ffmepg or ffmpeg-php to cut a 30 second clip or 60 second clip etc

Updating BIND Dynamically
I am about to start an indepth project for the company I work for. We want to use a PHP front end and be able to make updates to DNS dynamically. I was wondering if I can get some opinions on where to start.

Dynamically Populate PDF Form
I found a free script/class online a few months ago which enabled me to populate pre-built PDF forms with data using PHP; without using any toolkits etc (it worked perfectly). It was simply a PHP script. I lost the script when my PC died recently DOH!

Does anybody know where I can find such a script again? I have searched google all night, but all I find is commercial products (not cheap!) or toolkits for generating PDFs', not filling pre-built PDF forms. Here is what I am trying to do:

I have built a site for a client which incorporates e-learning. Students take lessons and if at the end of the course their grades are sufficient, they download a PDF certificate. The certificate is in PDF format with Form Fields for the required data. The certificate needs to display the students name, grade and course name. I need a PHP script which can import server-side data into a PDF form which the user can then print or save (flat). The last (and lost) script did this so I know it is possible.

PHP To Dynamically Make New Pages? DOH!
I am building a CMS system for a client to edit add and remove content from his new site, not a problem however he now wants the facility to create new pages and be able to edit the new pages, how do you create a new page dynamically using php and mysql?

As in he needs to make a new page called untitled2.php for example, with the title at the top of the page, a description about untitled 2 and then save the newly created page so it appears in the menu and actually exists in the remote server files, then be able to edit this using the CMS system? ERM...

Any standard commands as in create_page()?

How would I make the new page have variables included so that it could echo mysql content onto the newly created page?

Dynamically Transparent Gif's
Basically what i would like to do is dynamically set the transparency of a selection of images (GIF'S) depending on variables set in a My SQL Database. What i need to do is tint some jpg,s by setting the transparency of a solid blue gif which is set over the top of it in a table.

How To Append A Child Dynamically
i m new in both things php and in this group.
but i have some basic knowledge of php and DOM in php.

here is my problem,
i have one textfield for add a new main node (not main like:
<root><this_one></this_one></root>) in my php page and i m able to save
the xml file correct with this, and in the bottom of that i have one
new textfield for add new child in dynamically create node (which i
descibe above),and one combo box for show the all dynamically create
nodes.now i want that when user give the value in child textfield and
then select a root node for that child from combo box.i want to append
a child dynamically to root node.

but i m not able to do this. plz try to solve my prob...

Managing Subdomain Dynamically
i don't know if php can do it, here is the picture, what i want is a cheaper way of doing this stuff, newdomain.mydomain.com, cuz when i use the feature of the ISP, it will cost me $1/subdomain per month. any ideas?

Dynamically Load A Class
I want to dynamically load a class using a variable, e.g.

$module = new Mod_{$tmp_Name} ();

Where $tmp_Name is the name of the class.

Is there anyway to achieve this kind of thing?

Dynamically Embedding SWF File In PDF From PHP
is there by any means can i embed a swf file and export the same to a
pdf from my script.

Dynamically Updating Database
I have drop-down menus created on a previous page, created dynamically so the number of them varies. When the form is submitted I need a script that will automatically add 1 to the value in the playerTries column in the players table, for every drop-down menu. I've tried the code below but don't fully understand what's happening, and why it's not working. Code:

How To Get Value From A Dynamically Created Textbox
how to get value from a dynamically created textbox using php

Editing MP3s Dynamically
I'm trying to work out if there's a way of using PHP to dynamically edit an MP3. Is this a bit too much for the old PHP to handle? I just want to cut it down to 10 seconds of audio if possible.

Dynamically Create New Web Page
i'm making a cms, and I have a good portion done, I have it set up where the admin can log in and create a new post which goes to the database. I am just wondering how I can make this post a new web page? I have been trying to study how they do it in wordpress but with no avail. Anyone have any suggestions?

Dynamically Populate A Drop Down Box
I have a website with products for sale and along side each item I have displayed the number of each of these items that are left in stock.  What I want to do is to have a dropdown box so that the user can choose the qty of itmes to order but they should not be able to order more than what is in stock.

For example if there are 5 items left then the drop down box must be initialised at 0 and show the numbers 1,2,3,4,5.  When a purchase is made then the drop down must be adjusted to match what is left in the database. Code:

Dynamically Naming Variables
I'm pulling values from a db, the values are all domain names. Is there any way after pulling them in with a while loop, that I can define a variable name as the value of what I have pulled?

$query = "SELECT city FROM cities ORDER BY city";
$results = mysql_query($query);
while ($row = mysql_fetch_array ($results, MYSQL_ASSOC))
{
           $thisiswhereIwantTheValueToGo = $row['city'];
}

I understand that the above will make the value of the variable = to the $row['city'], is there any way I can dynamically create the variable name based on that same value?

Add Fields To A Form Dynamically On The Fly
I'm looking to create a form the allows the user to input a simple list item by item. However I am not sure how to implement a form that allows the user to add as many fields as the need on the fly.

Dynamically Create And Save Php Page
Here is my code:
$filepointer=fopen("http://www.mysite.org/usersetup/newusers/" . $SESSION_UID . "/configsite.php", "w+");

$data = "<? $name = ' . $datatosave. '
?>";

fputs($filepointer, $data);

fclose($filepointer);

My goal is to dynamically create a .php file with the contents of
<? $name = "variable data"; ?>

My code doesn't work. Something with the php page, I think. I and using similar code to populate .txt files with dynamic data, without variables, and it works file. Apparently, a quick change to .php is harder than I thought. I"ve even tried sending a simple line of data to the php page with no luck. Heck, I even tried doing it as a text file and rename to .php but it didn't like my rename.

Dynamically Generated Results Table
I'm trying to write a script that dynamically generates HTML tables depending on the results from an SQL query. So far, I have managed to set the HTML table headers to be the same as those in the MySQL table. [thanks to rod k -cheers !]

Now i'm trying to put the results in the table. Basically, I need a MySQL function to retrieve data and put it into the table until there is no data left....

(At the moment I am using "mysql_fetch_array()", but with this it is necessary to know the names of the columns to retrieve the information for each result set. Since my table is dynamic and should be able to build itself from different MySQL tables, the column names aren't fixed and so i can't use this to put the data in the tables...)

Getting Dynamically Generated POST Data
I'm trying to get POST data that was dynamically generated and I'm not sure how to go about doing this.

How To Dynamically Generate Functions In A Class
I am having to be tasked with a rather painful task of updating an
existing class by adding a dynamic amount of database field values;
for each database field value there has to be a generated array inside
the class plus a function "get method" to return it.

I do not want to have to constantly type out:

function getStuff() {
return $this->stuff;
}

for every occurrence of stuff I find that is generated by the database
SELECT call on the fields of as many as 20 different tables!! This is
enormous and I would love a more dynamic, functional method to
generate.. methods.

Saving A Dynamically Created Png Image
I have a web site that responds to a user request by sending an image generated dynamically. the request page call is something like this
<img id = "picid" src= "generateimage.php?$picName">

Where $picName holds the parameters needed for a particular image

generateimage.php sends the request to the server which generates the image as $pngstr and responds:

header("Content-Type: image/png".chr(13).chr(10));
header("Content-Length: ".strlen($pngstr).chr(13).chr(10).chr(13).chr(10));
echo $pngstr;

Now, I want the user to be able to right click the image and save it with a given name - related to but not exactly $picName, as a png.

I also have a set of images forming an animation generated in much the same way as the single image described above. How could I have the user save these? is there an animated png yet?

How To Get Full Address Of The Website Dynamically?
how to get full address of the website dynamically?
like www.yahoo.com/op/guy/123/
using server var($_SERVER).

i just want path till current working dir from www.yahoo.com/op/guy/123/ page.php i don't need it.

Dynamically Change META Tags
I am just wondering, if it is possible to dynamically change META tags through the use of PHP?

Any help is much appreciated. And yes, i am a beginner, on page 93 of Sam's PHP & MYSQL web development...

Dynamically Filling Selection Boxes
I was wondering if anyone knows how to fill a selection box with different values depending on a selection made in a nother selection box in the same page. I dont know if what I'm tryin to do can be done or not, at least in PHP. First a quick background:

We have a number of projects running right now, each of which is subdevided into various tasks. Now, I've got two selection boxes. The first contains a list of all current projects. What I want to do is this: when someon selects a project from the first box, I'd like the second box to be filled with a list of the tasks that have been assigned tot hat project.

Populating Dynamically Generated TextFields
If one assigns something to the value iattribute off an input /text field, that value will be displayed when the form is loaded. My problem is, when building a form dynamically, the only way I can get the text to show is by doing the above, however, as this is an update form, when the form POSTS to processUpdate.php,
both the data entered by the user AND the data in the value attribute are inserted/updated.

So, how does one dynamically build a form where the data is displayed in the text fields but value atttribute is not set. PHP Code:

Sizing A Text Area Dynamically
I have several text areas I am putting information from MySQL into. Right now they are 50 characters wide, by 10 rows. I want the number of rows to dynamically size do that the text area is the same size as the length of the data in MySQL.

I've tried all the logic I can think of... taking strlen and dividing it by the width... works great until they use line feeds... if someone puts:

"Hello... thanks."

the character count divided by the width is off. Here is the code I am using: Code:

Dynamically Created Image Into String
i have a dynamically created image represented by an imagehandler, but
i don't wanna output to the browser or a file. is it possible to read
that image directly into a string?

Highlight Dynamically Generated Text
I have a search form which makes queries to a database. In the form the user can search for many words (word1 && word2 && word3). I want in the results to highlight the words that the user has searched for. I 've searched in the internet and i've found some codes but none of them works with all the possible results.

What I have found so far which is closer to what I want is the following:

Downloading A Dynamically Built File
i'm trying to build a comma-separated file for my users to download summaries of information in the database. i did it once before and it worked fine, but this time it's in the context of a frameset and there are some problems. i have a form that calls the test script below, and the form's target is a hidden frame in my frameset. Code:

Are PHP Libraries Linked Dynamically Or Statically?
When a PHP program links to a library using include or require (or their
_once variations), is the library then linked dynamically or statically?

While it might seem irrelevant from a technical point of view, the
linking method is important when it comes to licencing issues as some
licences, like GPL, differ between those kinds of linking when it comes
to viewing the library as a derivative work of the main program.

Therefore it is quite important to know what kind of linking is in
effect when including libraries, and I hope someone in this group can
shed some light on this matter.

Dynamically Saving HTML Containing PHP Variables Through PHP
I have an HTML page with references to PHP variables. This HTML is
included from another PHP page. How can I save the HTML page
dynamically i.e. when all the PHP variables are written into the HTML
page.

How To Resize A Jpeg-file Dynamically
I have to resize an uploaded file dynamically with php. can you tell me how I could do that?

Dynamically Adding To Multidimensional Array
$sql= sql query
$i=0;

while
($a2=mysql_fetch_array($a1)){array_push($temparray ,$a2[0],$a2['ad'],$a2[1],$a2[1]);
{
I want this array to be the value of an asssoc. array $results[$i]
$results[$i] =$temparray doesnt work
$results[$i] =$temparray[] doesnt work
$results[$i][] =$temparray doesnt work
$results[$i] =>$temparray doesnt work

then $i++;
}
so what does ?


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