PHP only pulling 4 records

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

PHP only pulling 4 records

Post by tristanlee85 »

Code: Select all

<?php

mysql_connect("localhost","web11_u3","password");
@mysql_select_db("web11_db3") or die( "Unable to select database 1");

$query="SELECT * FROM xcart_products";
$result=mysql_query($query);
$num=mysql_numrows($result);

if ($num==0)
{
	$data .= "Something screwed up!";
}
else
{
$count=0;
while ($count < $num) 
	{
	$productid = mysql_result($result,$count,"productid");
	$productcode = mysql_result($result,$count,"productcode");
	$product = mysql_result($result,$count,"product");
	$provider = mysql_result($result,$count,"provider");
	$distribution = mysql_result($result,$count,"distribution");
	$weight = mysql_result($result,$count,"weight");
	$list_price = mysql_result($result,$count,"list_price");
	$descr = mysql_result($result,$count,"descr");
	$fulldescr = mysql_result($result,$count,"fulldescr");
	$avail = mysql_result($result,$count,"avail");
	$rating = mysql_result($result,$count,"rating");
	$forsale = mysql_result($result,$count,"forsale");
	$add_date = mysql_result($result,$count,"add_date");
	$views_stats = mysql_result($result,$count,"views_stats");
	$sales_stats = mysql_result($result,$count,"sales_stats");
	$del_stats = mysql_result($result,$count,"del_stats");
	$shipping_freight = mysql_result($result,$count,"shipping_freight");
	$free_shipping = mysql_result($result,$count,"free_shipping");
	$discount_avail = mysql_result($result,$count,"discount_avail");
	$min_amount = mysql_result($result,$count,"min_amount");
	$dim_x = mysql_result($result,$count,"dim_x");
	$dim_y = mysql_result($result,$count,"dim_y");
	$dim_z = mysql_result($result,$count,"dim_z");
	$low_avail_limit = mysql_result($result,$count,"low_avail_limit");
	$free_tax = mysql_result($result,$count,"free_tax");
	$product_type = mysql_result($result,$count,"product_type");
	$manufacturerid = mysql_result($result,$count,"manufacturerid");
	$return_time = mysql_result($result,$count,"return_time");
	
	$link = mysql_connect("localhost","web11_u4","password");
	@mysql_select_db("web11_db4") or die( "Unable to select database 2");
	$sql = "INSERT INTO xcart_products (productid, productcode, product, provider, distribution, weight, list_price, descr, fulldescr, avail, rating, forsale, add_date, views_stats, sales_stats, del_stats, shipping_freight, free_shipping, discount_avail, min_amount, dim_x, dim_y, dim_z, low_avail_limit, free_tax, product_type, manufacturerid, return_time) VALUES ('$productid', '$productcode', '$product', '$provider', '$distribution', '$weight', '$list_price', '$descr', '$fulldescr', '$avail', '$rating', '$forsale', '$add_date', '$views_stats', '$sales_stats', '$del_stats', '$shipping_freight', '$free_shipping', '$discount_avail', '$min_amount', '$dim_x', '$dim_y', '$dim_z', '$low_avail_limit', '$free_tax', '$product_type', '$manufacturerid', '$return_time')";

	mysql_query($sql);
	mysql_close($link);
	
	mysql_connect("localhost","web11_u3","password");
	@mysql_select_db("web11_db3") or die( "Unable to select database 3");
	
	$count++;
	}
}

echo "Done!";
It's kind of a quick hackjob and could be a lot cleaner, but basically I'm trying to pull information from one database and put it into another. I'm trying to move the products from my old X-cart version to the newer version. The code works, but it's only pulling 4 records and inserting them into the new database. There are 12 records that it should be pulling, but it's only doing 4.

I wasn't sure if this was necessasrily PHP or database related, so move where needed.
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

Post by potato »

your productid in your new version, is it auto-increment?
If so, try this instead of your insert:


Code: Select all

$sql = "INSERT INTO xcart_products (productcode, product, provider, distribution, weight, list_price, descr, fulldescr, avail, rating, forsale, add_date, views_stats, sales_stats, del_stats, shipping_freight, free_shipping, discount_avail, min_amount, dim_x, dim_y, dim_z, low_avail_limit, free_tax, product_type, manufacturerid, return_time) VALUES ('$productcode', '$product', '$provider', '$distribution', '$weight', '$list_price', '$descr', '$fulldescr', '$avail', '$rating', '$forsale', '$add_date', '$views_stats', '$sales_stats', '$del_stats', '$shipping_freight', '$free_shipping', '$discount_avail', '$min_amount', '$dim_x', '$dim_y', '$dim_z', '$low_avail_limit', '$free_tax', '$product_type', '$manufacturerid', '$return_time')";
I dont know if its this, just guessing...
Post Reply