fetching data from multiple tables

Hey everyone! i am trying to fetch data from multiple tables, but my code is displaying the data of only one table. I don’t know why it is showing data of single table…

here is my code

[php]

<?php $localhost="localhost"; $dbuser="root"; $dbpass=""; $dbname="shoppro"; $connect=mysql_connect($localhost,$dbuser,$dbpass); if ( !$connect ) { echo "Error connecting to database.\n"; } mysql_select_db("$dbname",$connect); $count = "select count(*)-1 from core_store_group"; $sql = ''; for($i=0;$i<2;$i++){ $sql="select name,price,short_description,sku,weight,promotion from catalog_product_flat_".$i; $result=mysql_query($sql); } while($row=mysql_fetch_array($result)){ echo $row['name']; echo "
"; } ?>

[/php]

Please help me !!

Your closing brace that appears immediately below this line:[php]$result=mysql_query($sql);[/php] should probably be after the closing brace of your while loop. Right now, you are overwriting your $result before you have used it.

See if this works better:[php]<?php
$localhost=“localhost”;
$dbuser=“root”;
$dbpass="";
$dbname=“shoppro”;
$connect=mysql_connect($localhost,$dbuser,$dbpass);
if ( !$connect )
{
echo “Error connecting to database.\n”;
}
mysql_select_db("$dbname",$connect);
$count = “select count(*)-1 from core_store_group”;
$sql = ‘’;
for($i=0;$i<2;$i++){
$sql=“select name,price,short_description,sku,weight,promotion from catalog_product_flat_”.$i;
$result=mysql_query($sql);

while($row=mysql_fetch_array($result)){
echo $row[‘name’];
echo “
”;
}
}
?>[/php]

There is some other stuff going on here, but I think this is the actual problem.

Sponsor our Newsletter | Privacy Policy | Terms of Service