MySQL / PHP Not inserting correct amount of entries -
hopefully quite simple someone.
i have following code:
<?php // connects database mysql_connect("localhost", "xxxxx", "xxxxx") or die(mysql_error()); mysql_select_db("xxxxx") or die(mysql_error()); require("../includes/common.php"); require("admin_header.php"); require("admin_menu.php"); $query = "truncate table pt_menutitles"; $result = mysql_query($query) or die(mysql_error()); // menu headers category $data = "select a.menuheader, a.total from(select distinct (menuheader),count(*) total `pt_products` `menuheader` <> '' group `menuheader` order total desc limit 4) order a.menuheader"; $result = mysql_query($data) or die(mysql_error()); while($info = mysql_fetch_array($result)) { $menudata = "select a.subcategory, a.menuheader,a.totcount from(select distinct (subcategory),menuheader,count(*) totcount `pt_products` `menuheader`='".$info['menuheader']."' , subcategory <> ''group `subcategory` order totcount desc limit 4) order a.subcategory"; $menuresult = mysql_query($menudata) or die(mysql_error()); while($menuinfo = mysql_fetch_array($menuresult)) { $sql = "insert pt_menutitles (menu, title, totalcount) select '".$menuinfo['menuheader']."','".$menuinfo ['subcategory']."','".$menuinfo ['totcount']."'"; $result = mysql_query($sql) or die(mysql_error()); } } ?>
basically take top 4 menu titles have items in them, select top 4 subcategories in them titles , insert them table.
what happening though i'm onlyt getting menu title 1 , subcategories 1 4 inserted table.
it's though the loop ending after first time round?
any advise great!
cheers chris
this line replaces existing result , ends loop. use other (non-existing) variable name, not $result.
$sql = "insert pt_menutitles (menu, title, totalcount) select '".$menuinfo['menuheader']."','".$menuinfo ['subcategory']."','".$menuinfo ['totcount']."'"; $result = mysql_query($sql) or die(mysql_error());
Comments
Post a Comment