Forum Moderators: open

Message Too Old, No Replies

can i run a query pulling 17 rows instead of 30?

can i run a query pulling 17 rows instead of 30?

         

john1000

6:46 pm on Aug 10, 2006 (gmt 0)

10+ Year Member



can i run a query pulling 17 rows instead of 30?

LifeinAsia

6:49 pm on Aug 10, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Yes.

john1000

7:51 pm on Aug 10, 2006 (gmt 0)

10+ Year Member



and how do i do that..
sample please....
in full...

LifeinAsia

9:07 pm on Aug 10, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Well, how are you limiting your existing query to 30 records? Just change that parameter to 17 instead of 30.

john1000

9:37 pm on Aug 10, 2006 (gmt 0)

10+ Year Member



well what needs to be done is this..
if i run this...

SELECT lid, cid, sid, title, url, description, date, name, email, hits, submitter, downloadratingsummary, totalvotes, totalcomments, filesize, version, homepage FROM downloads_deluxe

that works and grabs the proper fields/rows...

but then i need it to insert into another table like....

INSERT INTO my_downloads VALUES lid, cid, sid, title, url, description, date, name, email, hits, submitter, downloadratingsummary, totalvotes, totalcomments, filesize, version, homepage

that fails...

LifeinAsia

9:55 pm on Aug 10, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Why does it fail? What's the error message? And why do you think pulling only 17 rows instead of 30 will fix anything?

FalseDawn

10:00 pm on Aug 10, 2006 (gmt 0)

10+ Year Member



I think he is referring to the number of columns, but it's still not clear exactly what he is trying to do.

LifeinAsia

10:14 pm on Aug 10, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



That's what I thought, but both tables have 17 columns. Clarity would certainly help expedite a solution. :)

john1000

10:17 pm on Aug 10, 2006 (gmt 0)

10+ Year Member



well...i have a table...
it has 30 fields..or rows..whatever you wanna call it...

i wanna grab info from 17 rows of that table...

and then insert it to another table (a new one)

All fields/rows etc have the same names..

so thats the question realy...

so i thought something like...

$sql = 'SELECT lid , cid , sid , title , url , description , date , name , email , hits , submitter , downloadratingsummary , totalvotes , totalcomments , filesize , version , homepage FROM old_downloads ';

and then somehow then do...

INSERT INTO....etc..
but thats where im stuck..

john1000

10:29 pm on Aug 10, 2006 (gmt 0)

10+ Year Member



so to be clear...i wanna grab some info...from table 1 and after that i wanna put it in table 2..

LifeinAsia

10:30 pm on Aug 10, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Fields and rows are completely different. You need to explain which you mean, because the solutions for each are completely different.

A field (or column) is one piece of data (e.g., date, name, etc.). A row of data is a collection of data, 1 entry for each field. It's not exactly accurate, but think of a database like an Excel spreadsheet.

Now, once you get the demantics correct, telling us the exact error message(s) you get should bring a solution almost within reach...

john1000

10:45 pm on Aug 10, 2006 (gmt 0)

10+ Year Member



Well this deffinately doesnt work so dont laugh please...

What i want is this..

<?php
$db = mysql_connect ("localhost", "username", "password")
or die("no connection: " .mysql_error());
mysql_select_db("my_test", $db);

$sql = "SELECT lid , cid , sid , title , url , description , date , name , email , hits , submitter , downloadratingsummary , totalvotes , totalcomments , filesize , version , homepage FROM old_downloads".
"VALUES ('$lid, $cid, $sid, $title, $url, $description, $date, $name, $email, $hits, $submitter, $downloadratingsummary, $totalvotes, $totalcomments, $filesize, $version, $homepage')";


$sql = "INSERT INTO new_downloads (lid, cid, sid, title, url, description, date, name, email, hits, submitter, downloadratingsummary, totalvotes, totalcomments, filesize, version, homepage)".
"VALUES ('$lid, $cid, $sid, $title, $url, $description, $date, $name, $email, $hits, $submitter, $downloadratingsummary, $totalvotes, $totalcomments, $filesize, $version, $homepage')";

if (!mysql_query($sql)) {
echo "Faild";
} else{
echo "succes";
}
mysql_close($db);
?>

i know i completely fail with this...
the first part does work but inserting the results into is a mess..

i simply get...Faild

LifeinAsia

11:17 pm on Aug 10, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



You should return the error message you're getting instead of just "faild" to really help you troubleshoot your code. For most modern programming languages/databases, error messages are great aids in helping you fix the errors.

I don't know enough PHP or MYSQL. So I don't understand why you have the VALUES part after the select statement (1st $sql).

If the field names and types match exactly, the following should work with MSSQL. But you can try to modify accordingly:

INSERT new_downloads
SELECT *
FROM old_downloads

(MSSQL allows a little sloppiness with INSERTs, so you may need to change the first line to "INSERT INTO new_downloads" to get it to work.)

I still don't understand how the original question about 17 vs. 30 rows fits into any of this.

john1000

11:25 pm on Aug 10, 2006 (gmt 0)

10+ Year Member



well that was indeed a nice idea but there was a reason why i just want to grab 17 fields/rows...
it has 30...
so with your sample it can never work,cause it grabs 30 fields and dumps it into a table that has only 17.

LifeinAsia

11:32 pm on Aug 10, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Huh? What are you talking about? Your example only listed 17 fields for both tables.

Again, are you talking about fields or rows? They are more different than apples/oranges.

john1000

11:43 pm on Aug 10, 2006 (gmt 0)

10+ Year Member



Let me explain with real tables...

THIS TABLE AND ITS CONTENTS :

CREATE TABLE `old_downloads` (
`lid` int(11) NOT NULL auto_increment,
`cid` int(11) NOT NULL default '0',
`title` varchar(100) NOT NULL default '',
`url` varchar(255) NOT NULL default '',
`description` text NOT NULL,
`date` datetime NOT NULL default '0000-00-00 00:00:00',
`name` varchar(100) NOT NULL default '',
`email` varchar(100) NOT NULL default '',
`hits` int(11) NOT NULL default '0',
`sid` int(11) NOT NULL default '0',
`downloadratingsummary` double(6,4) NOT NULL default '0.0000',
`totalvotes` int(11) NOT NULL default '0',
`totalcomments` int(11) NOT NULL default '0',
`icon` varchar(255) default NULL,
`submitter` varchar(60) NOT NULL default '',
`sub_ip` varchar(16) NOT NULL default '0.0.0.0',
`filesize` bigint(20) NOT NULL default '0',
`version` varchar(20) NOT NULL default '',
`homepage` varchar(255) NOT NULL default '',
`active` tinyint(2) NOT NULL default '1',
`price` decimal(8,2) NOT NULL default '0.00',
`currency` varchar(4) NOT NULL default 'EUR',
`sale` tinyint(2) NOT NULL default '0',
`image` varchar(255) NOT NULL default '',
`share` tinyint(1) NOT NULL default '0',
`previewtrue` tinyint(2) NOT NULL default '1',
`mediacheck` char(3) NOT NULL default 'mp3',
`previewurl` varchar(255) NOT NULL default '',
`presentationurl` varchar(255) NOT NULL default '',
`keywords` text NOT NULL,
PRIMARY KEY (`lid`),
KEY `lid` (`lid`),
KEY `cid` (`cid`),
KEY `title` (`title`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;

HAS TO BE REPLACED WITH THIS TABLE :

CREATE TABLE `new_downloads` (
`lid` int(11) NOT NULL auto_increment,
`cid` int(11) NOT NULL default '0',
`sid` int(11) NOT NULL default '0',
`title` varchar(100) NOT NULL default '',
`url` varchar(100) NOT NULL default '',
`description` text NOT NULL,
`date` datetime default NULL,
`name` varchar(100) NOT NULL default '',
`email` varchar(100) NOT NULL default '',
`hits` int(11) NOT NULL default '0',
`submitter` varchar(60) NOT NULL default '',
`downloadratingsummary` double(6,4) NOT NULL default '0.0000',
`totalvotes` int(11) NOT NULL default '0',
`totalcomments` int(11) NOT NULL default '0',
`filesize` int(11) NOT NULL default '0',
`version` varchar(10) NOT NULL default '',
`homepage` varchar(200) NOT NULL default '',
PRIMARY KEY (`lid`),
KEY `lid` (`lid`),
KEY `cid` (`cid`),
KEY `sid` (`sid`),
KEY `title` (`title`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;

So you see...
The first table is BIGGER...

But im not gonna use these anymore..!

`icon` varchar(255) default NULL,
`sub_ip` varchar(16) NOT NULL default '0.0.0.0',
`active` tinyint(2) NOT NULL default '1',
`price` decimal(8,2) NOT NULL default '0.00',
`currency` varchar(4) NOT NULL default 'EUR',
`sale` tinyint(2) NOT NULL default '0',
`image` varchar(255) NOT NULL default '',
`share` tinyint(1) NOT NULL default '0',
`previewtrue` tinyint(2) NOT NULL default '1',
`mediacheck` char(3) NOT NULL default 'mp3',
`previewurl` varchar(255) NOT NULL default '',
`presentationurl` varchar(255) NOT NULL default '',
`keywords` text NOT NULL,

Now...i cant be clearer then this.. :(

LifeinAsia

11:59 pm on Aug 10, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Did you think about trying this?
INSERT new_downloads
SELECT lid, cid, sid, title, url, description, date, name, email, hits, submitter, downloadratingsummary, totalvotes, totalcomments, filesize, version, homepage FROM old_downloads

However, your new table has smaller sizes for some of the fields (example- url is VARCHAR(255) in old_downloads, but only 100 in new_downloads), so you'll need to trim some of the data. I don't know what you use in PHP/MYSQL- "substr" maybe?

For future reference, if you had originally asked how to copy data from a table with 30 fields into a table with 17 fields, the solution would have arrived much sooner. You may want to check out this link: [catb.org...]

[edited by: LifeinAsia at 12:06 am (utc) on Aug. 11, 2006]

john1000

2:03 am on Aug 11, 2006 (gmt 0)

10+ Year Member



hello,

thanks...im deffinately gonna try this after some sleep so im back on this in about 7 hours or so..

as you said........I don't know what you use in PHP/MYSQL- "substr" maybe?

what you mean by that...
keep in mind that my knoweledge is limited... :)

but as soon as i tried your sample ill get back..

thanks so far :)

john1000

11:06 am on Aug 11, 2006 (gmt 0)

10+ Year Member



thanks lifeinasia....
you saved my day....
it realy worked flawless...

i will try to do the same with the categories....
thanks again :)