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




Copying Rows To Another Table


After I select a row whose ID is 10 or some other number, I need to
copy the entire row into another table.

Is there a way to copy rows between tables using PHP? Could someone
please point me to an example..




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Copying Values From One Table To Another Problem?
I'm trying to copy some values from 10 tables to one table.

So i made a PHP script to do it automaticaly every time the user select an specified option.

How Many Rows In A Table
I am sure there must be an easy way to determine the number of
rows in a table, but I can't find it.

New Table Rows
I retrieve 20 items from a MySQL database. I want to display the output in a table. How can I display 5 items on a table row and then begin an new row?

Eliminate Gap Between Table Rows?
I made my first PHP page that uses includes.
http://php.didah.com/main.php
But I can't get rid of a gap (about 5 pixels) between the table rows.

The content of each include file is one line like this:
<img src="images/nav.gif" width="100" height="600" hspace="0"
vspace="0" border="0">
No head or body tags. Just a 100 x 600 gif image.

Here's the code for the main.php page:

<html>
<head>
<title>First Include Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="600px" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td colspan="2"><?php include 'header.php' ?>
</td>
</tr>
<tr>
<td><?php include 'nav.php' ?></td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>This is the content area.</td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="2"><?php include 'footer.php' ?></td>
</tr>
</table>
</body>
</html>

If you look at the main page in IE there is a vertical gap between the
header, nav, and footer image. Does anyone know how to get rid of this?

Selecting Rows From Db Table
In a project mentioned in another thread, I'm trying to get some
dynamic data to work. In this discography, you can click on an
album name, and the title of the album and its tracks will appear
on the left. I have the beginnings worked out, like so:

***

<h3><?php echo $row_rsindiv['Album']; ?></h3>
<ol>
<?php do { ?>
<li><?php echo $row_rsindiv['Song']; ?> (<?php echo $row_rsindiv
['Time']; ?>)</li>
<?php } while ($row_rsindiv = mysql_fetch_assoc($rsindiv)); ?>
</ol>

***

A sample of the database:

***

Electronic Meditation 3 Cold Smoke 10:48
Electronic Meditation 4 Ashes to Ashes 3:58
Electronic Meditation 5 Resurrection 3:21
Alpha Centauri 6 Sunrise in the Third System 4:20
Alpha Centauri 7 Fly and Collision of Comas Sola 13:23
Alpha Centauri 8 Alpha Centauri 22:04
Zeit 9 Birth of Liquid Plejades 19:52
Zeit 10 Nebulous Dawn 17:47

***

I want to tell PHP to write the album name and list the tracks in
an <li></li> based on whatever album title is clicked in the main
table.

The main table looks like:

***

<?php do { ?>
<?php
$class = ($class == 'odd') ? 'even' : 'odd'
?>
<tr class="<?php echo $class ?>">
<td><?php echo $row_rstdream['Album']; ?></td>
<td><?php echo $row_rstdream['Year']; ?></td>
<td><?php echo $row_rstdream['Era']; ?></td>
<td><?php echo $row_rstdream['Type']; ?></td>
</tr>
<?php } while ($row_rstdream = mysql_fetch_assoc($rstdream)); ?>

***

I thought maybe of changing the first <td></td> to:

<td><a href="#" onclick="<?php $album = $row_rstdream['Album'] ?>">
<?php echo $row_rstdream['Album']; ?></td>

But that's as far as I can get with my limited knowledge. Does
anyone have any ideas on how to display only the rows in the second
database that correspond to the name of the album clicked on? Sorry
the examples are so long,

How Do You Find Out How Many Rows Are In A Table?
How can you tell(using php) how many rows are in a database table.

Duplicating MySQL Table Rows
I'm not sure whether this should be posted here on in databases, but it's a question about inserting records in a MySQL table using PHP.

I have a large table with some 50+ fields with an auto-increment primary key field. When a record is edited by a user, we need to duplicate the original record, and update the fields changed by the user.

My question is, what is the easiest way to capture and duplicate the original table row? Yes, I could read the record in and then loop through the $row[] array using this as the source of all fields (except the primary key), but it strikes me that there must be a simpler method.

Navigation Through Mysql Table Rows.
I am running a query on a master detail page which results in a number of records. I call this page the master detail page. The master detail page has a number of records listed as thumbnails. Each thumbnail has a link identifier which is linked to a detail page. On the detail page I have no problem querying the specific recordset through $HTTP_GET_VARS['id'] and the additional info below. PHP Code:

Help With Randoming Pulling Out Rows Of A Table
Suppose I'm connected to a database and I do the following:

$query = "Select q_id, question From questions Order by q_id";

$result = mysql_query($query);

Now, what is the best way to pull out 20 random rows from my questions
table?

I'm trying to set up on an online trivia page where different
questions are posted each time a person visits the page and I'm
pulling my list of questions out of a database.

I know mysql_fetch_array fetches one row at a time and array_rand can
pull elements out of an array at random, but I'm at a loss at how to
coordinate these two functions together to do what I want to do.

Selecting Random Rows In A Table.
How can i randomly select rows? say for example i have 50 users, 3 of them were online. I only want the 3 online, BUT i want then to be randomly choose. So that everytime i go to the page, it is a different person. Im assuming MySQL numrows has something to do with it but im not quite sure.

How Do I Delete Selected Rows From MySQL Table?
I am trying to figure out how to delete selected rows from a MySQL database table. The web site that I am working on has a page that will extract rows, using the "SELECT * FROM .. etc." statement from a database and output them in a table - like the one below (bottom part). I've got that part figured out.

What I am trying to figure out is if the user puts a checkmark in one of the checkboxes (below) how would I write the PHP code to delete one or two of the rows from the MySQL table? PHP Code:

Looped Rows In Table Add & Remember Values
I'm trying to get this app to work. It's supossed to:

1. create rows dynamically through a loop (done)
2. remember the user-entered-values while the form posts to itself
3. provide a total (addition) of all 4 rows. (kinda tricky since the rows are looped).
PHP Code:

Parse HTML Table Rows Into Array
I have a script that extracts an HTML table from a page into a text string. I would like to parse each row of the table into an array named "$rows". I would like to keep the html intact so that I could re-create the same table like: Code:

Adding Multiple Rows To Table Using Checkboxes
I'm looking to select using checkboxes certain rows from the results of 'table a' and add the selected rows to another table using checkboxes. I Have had limited success adapting some code for deleting multiple records using checkboxes. Code:

Dynamically Create Table Rows As Needed
I have a form with a table. Each table row has a ID= "some number". I have 4 rows and might need to create more. how can i do this in php? To go along with this, When I hit the submit buton, I then need all the table row data saved to a db i have. I can insert 1 line with out a issue. I also made sure the table row name="" fields are unique. ex. Code:

Updating Multiple Rows In A Table In Mysql
ok so im making this form that updates multiple rows in the mysql database but the thing is that the number of rows is a variable so once it may be one row once it may be 31 rows. is there anyway i can do this using a while loop? or even is there a way to do this period?

Displaying Multiple Queries To Same Table Excluding Different Rows!
i've got a table with 224 town listings and their ID's in it from 6 counties, and I want it to displayin a 6 columned table, each county getting their own column. Anyway, here's what I've got and what's happening: PHP Code:

Using Php To Move Rows From Text File Into Mysql Table
Can anyone point me in the right direction for the way to read a text file a
line at a time and separate the fields on that line and use them as data in
an INSERT to add a record to a mysql table. Then read the second line in
text file and repeat.

Divide Mysql Results Into Rows In An Html Table
I need to divide my mySQL results into rows with 4 results on each row. Its for a small image gallery script, I wanna show 4 thumbnails per row. I have all the code ready to get the info and show it, I just need an example of how I can take the data from the table and have it automatically go to a new row every 4 entries.

ECHO The Amount Of Rows In My Table According To A Specific Username
I am creating an infinite loop with this code. My goal is to just ECHO the amount of rows in my table according to a specific Username. How do I do this? my code:

<?php $query = "SELECT ID FROM products WHERE Username = '{$Username}'"; 
$result = mysql_query($query) or die(mysql_error());
$row = mysql_num_rows($result) or die(mysql_error());
$num = 0;
while ($num <= $row) {
echo $row;}?>

Ordering & Limiting Multiple Table Rows By Date
My goal is to select rows from two tables 'shoot' & 'video' and have mysql order those tables by date and limit the number of rows returned. I want to list the latest 10 rows but am uncertain how many rows from each table will be the latest. I may have more recent shoots than videos or the opposite. How can I use a single ORDER BY and LIMIT statement for both selections? Code:

Code To Make Table Rows Of A Result Appear In Alternating Colours...
How can I get it so that when I run a search, and the results come back in table format, the rows are alternating colours, like on Devshed's forums? I believe there was some code here some time ago saying how to do it..

Count Rows In Table By "category"
I have a table full of articles. One of the columns is "category". I want to count how many arcticles there are for each category. I have another table that lists all the categories. I see two ways to do this, but don't know which is best or easier.

One way I think would be to somehow count how many rows had the same category in just the articles table (they are entered by number). This way would be ok, but would only list categories that had articles (which in some cases I would want to do).

The other way would be to query the select * from categories, and somehow join it to the articles table while counting how many articles there were for each category (even if they were zero).

Multiple Table Rows In "While" Loop
I have the code below with two table rows, but the second row won't display any data. How can I make both table rows work? Code:

Creating Table Rows For Ever Other Loop In A WHILE Loop
I'm trying to create a table using a MySQL fetch array while loop that would look like this:

CONTENT1     CONTENT2
CONTENT3     CONTENT4
CONTENT5     CONTENT6

I need a <TR></TR> for every other piece of content. But I don't know how to do this with a loop that uses a MySQL fetch array

while($row = mysql_fetch_array($result, MYSQL_ASSOC))

{
PHP CODE THAT IS LOOPED;};

I'm trying to remember from my old college Java class that we did something with loops for whenever the counter variable was even the loop would do something special... I don't know if this is possible with a while+mysql_fetch_array loop though.

Count Amount Of Rows In Same Query Of Selecting Rows
I am selecting some rows from a table and i wonder if i can count
the amount of rows in that same table in the same query? I tried something like: PHP Code:

Copying Files
The situation is I have a template.php file, and I wan't my script to copy this file and give the new copy a new name.

This is the code so far, but it doesn't copy...

$temp = "template.php";
$file = $linktextdata . ".php";

if (!copy($temp, $file)) {
echo "copy of $temp failed";
}

I test echoed the variables, and they look ok.

Image Copying
I have this form tag to send an image to my message board: <input type=file name=picture> and the enctype="multipart/form-data" in in the form tag. I them use $picure_name to do two things.

First, I alter the message the include the img tag using str_replace. That part works fine. I then try to copy the message to the images directory:exec("cp $picture /full/path/to/mbimages/$picture_name");

The image never gets there. I don't get any error messages, but the image never shows up in that directory.

Copying A Directory
I think i can use copy() to do this, but i just dk how :S.  i can only get it to copy files.

I need a script that can copy a folder, and all the files in that folder, and "paste" it in a new directory. 

Copying Remote Files
How do i copy a picture or another file from a remote webpage, and put it into my webpage dir?

Copying From One Mysql Database To Another
Is it possible to open a connection to two separate mysql databases in order to copy the data from one table in the first database into a table in the second database? I'm assuming the answer is yes, but I'm confused as to the proper php syntax.

Files And Folder Copying
I am trying to write a function to copy an existing folder and folder
structure but am already stuck.

What I want to do is the following:

Copy a default folder (default_folder) and all sub folders within it (down
to a possible 4 levels)
eg default folder
->subfolder1
->subfolder2
->sub subfolder1
->sub sub folder 2

I have a form where the user can enter the name of the new folder and an
option to confirm if they want to copy the files also located within the
default folder.
If the checkbox is not checked then copy just the folder structure only

Can this be acheived in one function or will it be based on 2 where a set of
empty folders are created and where the folders and files are copied over

Copying Entire Directories
I need to copy all of the files from one directory to another. This has to happen on the fly. The files that are being copied are actually templates for another site that will be created. I have seen the example on php.net under the fopen section but it doesnt work.

Copying Files From One Server To Another
I am trying to set up a link excahnge program using php and I need to know how to copy a file from one server to another. See when people change the banner they have displayed they can enter the location of their banner, such as http://them.com/banner.gif and then i need to copy it over to my server and into there dir, such as www.me.com/them/banner.gif. Does anyone know how i can do this. I have tried many things but nothing has workd so far.

Copying Old Folders To A New Location
I'm trying to write a page that would make a copy of a set of folders to a new location for an intranet. There is lots in the page for debugging that would vanish once I get it to work. The problem I'm getting is I cannot get XCOPY to work. Other dos commands work fine. Code:

Copying A File From On Server
Let's say I have a file on my server at location:

/public_html/Global/oilers.php

...and i want to copy this file and save it to another directory (using ftp commands):

/public_html/hockey/Oilers/oilers.php

How would I go about....   I gigured out how to login using ftp commands and explored the ftp command available.. (eg.put, get etc..) but I'm not sure which command to use..  can someone point me in the right direction?

Copying Files Using A Loop
I have a spreadsheed with names and image urls that I have converted to a tab delimited text file. Column one has the product  name and column two has a url to an image on another site.

I am trying to loop through the file and copy the image onto my computer, but it is giving me this error: "Warning: copy(http://ec1.images-amazon.com/images/I/41Oj92a63gL._AA280_.jpg ) [function.copy]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in C:Program Filesxampphtdocscopy.php on line 16" Code:

CopyDir (Copying One Directory To Another)
I was wondering if it was posible for someone to point me in the right direction.

What i need to do it copy the contence of an entire directory to another designated destination, is this possible and if so could someone point me somewhere i where i can figure it out.

Copying A Multidimensional Array To $_SESSION
Specifically, is it possible to copy a multidimensional array into the
$_SESSION array - ie a deep clone of all keys and data?

I naively assumed that

$_SESSION["myArray"'] = $myArray ;

would work but it doesn't appear to work. Is there a single function
or assignment I can use, or would I need to use a "foreach" at every
level?

Error While Copying Files After Upload
I'm trying to allow users to upload to the server. The system seems to upload okay (at least it takes a while for the page to refresh after the submit button is pressed). When the submit button is pressed and the files are uploaded, it reloads the script (a $PHP_SELF in the form tag).

What happens next is that it tries to copy the uploaded files (a maximum of 3 files can be uploaded) to a more permanent directory on the server. code:

Copying Variable Part Of A String
I have strings like these:

$line = "Item <name> xxx stock, costs yyy and will sell for amount zzz";

Problem is <name> can consist of 1..n words. Most items are single words,
but some are up to 8 in my example, and there are is no set maximum (well,
max is 80 chars I believe, have to look in the stock db, not too relevant I
think)
I found this out the hard way. I thought I was clever (never do that again)
by doing this:
$words = explode (" ", $line);
$itemname = $words [1];

This only works for single-word names.

Now I want to create or use an existing function that simply copies
everything between Item and the first numerical substr.
The function then should look like:

$itemname = GetSubStr ("Item" , <numerical> , $line);
<numerical> should be a template of some sort I think.

Controlling The Copying Of Images From A Site
Is there a way to prevent users copying a full size image from a web page.
Displaying the image with a smaller width and height only affects the image
as viewed, the actual full size image file is still downloaded. I know I can
get around it by having two versions of an image, the full size one and a
smaller on for display purposes. but is there a way around having to have
two images and use the full ssize one and stop it being copied or if copied
will only be a thumbnail?

Copying File From Hosted Remote Sever To Local Machine
I am trying to use php to automate the copying of a file from my remotely
hosted directory to my computer. I have put together the following but it
will only do the copying from one directory to another on the remote server.
Reading the postings on these functions they suggest that it can be done but
it appears to be the case if your are hosting your site on the same machine
you want to copy the files to. Does anyone know if there are functions in
php to do the transfer from remote server to my machine or if the code below
will acheive this with modification?

<?php
$ftp_server = "xxxxxxxx";
$ftp_user = "xxxxxxx";
$ftp_pass = "xxxxxx";
$local_file = 'myfile.txt'
$server_file = 'myfile.txt'

// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to
$ftp_server");

$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);

// check connection
if ((!$conn_id) || (!$login_result)) {
die("FTP connection has failed !");
}

// try to change the directory to myfilesdirectory
if (ftp_chdir($conn_id, "myfilesdirectory")) {
echo "Current directory is now: " . ftp_pwd($conn_id) . "";
} else {
echo "Couldn't change directory";
}

if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
echo "Successfully written to $local_file";
} else {
echo "There was a problem";
}

// close the connection
ftp_close($conn_id);

Grab Content From HTML Table And Place Into MySQL Table?
I am in the process of helping a co-worker upgrade some of his old static html pages into dynamic MySQL driven pages. He currently has a lot of pages with huge tables displaying data. Does anyone know if there is a script or class that can convert a table to a .sql file for upload?

Table Background Color Based On Results From MySQL Table
I am trying to get the "Did User Agree" field on a database query to be colored Green for "Agreed" Red for "Disagreed" and Blue for "Agreed (2nd Time)" .. I have my PHP setup to do the query just fine as of right now with alternating column colors, just can't seem to get the colors to work as I am hoping for.  Can anyone help me get the Agreed? table's background color to the colors above? Code:

Outputting A Table Or Form Using SHOW FIELDS FROM Table
In the code the MySQL database was queried using "SHOW FIELDS FROM table" which and the returned results of column names was then use to build an output for a form and a table with php using a series of if statements along the lines of if the returned field name matches something echo a text input field.

I have never seen this done this way before, so I want to get the opinion of the devshed user. Does it seem like an unsual long process to build up a form. Is there a security advantage doing it this way? Has anyone ever done it this way before?

Finding Matches In A Table And Then Moving That Match To Another Table?
Ok, I have a database that has a table called critiera in this table
is to fields on is ID and the other is critiera.

Now I want to filter out all the one that don't apple to the list and
move the one that match to a different database.

I know how to open a connection, close, select

but I don't know how I would inside of a database use another one as
the way to create the list of critieras....

Mysql Fetch_field Gets Table Alias, Not Real Table Name
After a SQL 'select .... from tablename alias'
the mysql_fetch_field function returns a value $result=>table which
will contain the alias, not the actual table name.
Is there a way to get the actual table name ?

I am running mysql 4.1 and php 4.4

Grab Data From A Table, Echo, Then Insert It Into A New Table...
I'm trying to do is count the number of times usernames shows up in a table. I then want to reinsert that information into a different table with the Username in column1 & the occurrences in column2 for every user that is echoed on the page. Code:


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