piznac Posted January 30, 2007 Share Posted January 30, 2007 Ok I have two tables in a rather small database. One holds 3 fields one being a "store number". The other holds info about projects completed for these stores. What I need is to lisst the stores and the projects completed. I can do this,. but not the way I want. I want it to be like this:Store#1 = project1,project2,project3,..etc.Store#2 = project1,project2,project3,..etc.The only thing I can get is:Store#1 = project1Store#1 = project2Store#1 = project3,..etc.Store#2 = project1,..etc.I know there must be a way to do this, but am unsure how. This is what I have so far:[code]<?php require_once('../../Connections/conner.php'); ?><?php$dm = $_GET['dm'];mysql_select_db($database_conner, $conner);$query_dmstore = "SELECT * FROM dmrmst";$dmstore = mysql_query($query_dmstore, $conner) or die(mysql_error());$row_dmstore = mysql_fetch_assoc($dmstore);$totalRows_dmstore = mysql_num_rows($dmstore);?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title></title></head><body><?php do { ?> <?php $num = $row_dmstore['store']; ?> <?php$numbs = explode(" ", $num);foreach($numbs as $value){mysql_select_db($database_conner, $conner);$query_store = "SELECT * FROM pog_check WHERE `storenum` = '$value'";$store = mysql_query($query_store, $conner) or die(mysql_error());$row_store = mysql_fetch_assoc($store);$totalRows_store = mysql_num_rows($store);$pog = $row_store['storenum'];$pogs = explode(" ", $pog);foreach ($pogs as $value2){echo "$value2 = $row_store[pogtype]<br>";}}?> <?php } while ($row_dmstore = mysql_fetch_assoc($dmstore)); ?></body></html><?phpmysql_free_result($dmstore);mysql_free_result($store);?>[/code]I know this is probably all wrong,. but I cant seem to wrap my head around this. Any help would be great,.. and if you need more info please tell me. Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted January 30, 2007 Share Posted January 30, 2007 maybe this will shed some light on things:[code]<?php $sql1 = "SELECT store_number FROM stores_table"; $query1 = mysql_query($sql1); while($storenum = mysql_fetch_array($query1)){ $sql2 = "SELECT project FROM projects_table WHERE store_id = ". $storenum['store_number'] .""; $query2 = mysql_query($sql2); $projects_array = array(); while($row = msyql_fetch_array($query2)){ $projects_array[] = $row['project']; } $string = explode(", ", $projects_array); echo "Store#". $storenum['store_number'] ." = ". $string ."<br />\n"; }?>[/code] Quote Link to comment Share on other sites More sharing options...
piznac Posted January 30, 2007 Author Share Posted January 30, 2007 Ok sorry now Im even more confused. Now Im getting a inf loop of the first store number. Here's what I have:[code]<?php require_once('../../Connections/conner.php'); ?><?php$dm = $_GET['dm'];mysql_select_db($database_conner, $conner);$query_dmstore = "SELECT * FROM dmrmst";$dmstore = mysql_query($query_dmstore, $conner) or die(mysql_error());$row_dmstore = mysql_fetch_assoc($dmstore);$totalRows_dmstore = mysql_num_rows($dmstore);while($totalRows_dmstore = mysql_num_rows($dmstore)){mysql_select_db($database_conner, $conner);$query_store = "SELECT * FROM pog_check WHERE `storenum` = ". $row_dmstore['store'] ."";$store = mysql_query($query_store, $conner) or die(mysql_error());$row_store = mysql_fetch_array($store);$totalRows_store = mysql_num_rows($store); while($row_store = mysql_fetch_array($store)){ $projects_array[] = $row['pog_type']; } $string = explode(", ", $projects_array); echo "Store#". $row_dmstore['store'] ." = ". $string .""; }?> [/code] Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted January 30, 2007 Share Posted January 30, 2007 that's because you've got it wrong. i've taken a look at your code, and tried to see what it is you want to do... try this:[code]<?php require_once('../../Connections/conner.php'); $dm = $_GET['dm']; mysql_select_db($database_conner, $conner); $query_dmstore = "SELECT * FROM dmrmst"; $dmstore = mysql_query($query_dmstore, $conner) or die(mysql_error()); $totalRows_dmstore = mysql_num_rows($dmstore); echo "Total number of stores: ". $totalRows_dmstore ."<br />\n"; while($row_dmstore = mysql_fetch_array($dmstore)){ $query_store = "SELECT * FROM pog_check WHERE storenum = ". $row_dmstore['store'] .""; $store = mysql_query($query_store, $conner) or die(mysql_error()); while($row_store = mysql_fetch_array($store)){ $projects_array[] = $row['pog_type']; } $string = explode(", ", $projects_array); echo "Store#". $row_dmstore['store'] ." = ". $string ."<br />\n"; }?>[/code] Quote Link to comment Share on other sites More sharing options...
piznac Posted January 30, 2007 Author Share Posted January 30, 2007 Still coming up with the same thing my friend. Here is the page:[url=http://www.connerandassociates.com/pog_check/man/test_print2.php]http://www.connerandassociates.com/pog_check/man/test_print2.php[/url]Im a bit confused about this[code]$string = explode(", ", $projects_array);[/code]Wouldnt that turn it into an array? Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted January 30, 2007 Share Posted January 30, 2007 hmmm... well you're not getting an infinite loop of the same store, anymore which is good.yes you are right... it should be implode, not explode. just replace this:[code]$string = explode(", ", $projects_array);[/code]with this:[code]$string = implode(", ", $projects_array);[/code]and see what happens. Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted January 30, 2007 Share Posted January 30, 2007 can you display what your database tables look like? just the field names and the first few entries will be fine. i want to make sure we're calling the right columns in the right place... and what values we're looking for. Quote Link to comment Share on other sites More sharing options...
piznac Posted January 30, 2007 Author Share Posted January 30, 2007 Sorry I seemed to be having a bit of trouble doing what you asked,.. give me a few mins. Quote Link to comment Share on other sites More sharing options...
piznac Posted January 30, 2007 Author Share Posted January 30, 2007 ok the store tables is something like thisdmrmst:rm---------------dm-------------[color=red]store[/color]name------------name-----------store#2nd one is like this:auditready,followup,poponorder,displayorder,other,explain,date,pogtype,[color=red]storenum[/color],num,dm Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted January 30, 2007 Share Posted January 30, 2007 what's the name of your second table? is it pog_check?and don't forget that you need to reset OR unset $projects_array:[code]<?php require_once('../../Connections/conner.php'); $dm = $_GET['dm']; mysql_select_db($database_conner, $conner); $query_dmstore = "SELECT * FROM dmrmst"; $dmstore = mysql_query($query_dmstore, $conner) or die(mysql_error()); $totalRows_dmstore = mysql_num_rows($dmstore); echo "Total number of stores: ". $totalRows_dmstore ."<br />\n"; while($row_dmstore = mysql_fetch_array($dmstore)){ $query_store = "SELECT * FROM pog_check WHERE storenum = ". $row_dmstore['store'] .""; $store = mysql_query($query_store, $conner) or die(mysql_error()); $projects_array = array(); //<--- you can reset it here while($row_store = mysql_fetch_array($store)){ $projects_array[] = $row['pog_type']; } $string = explode(", ", $projects_array); echo "Store#". $row_dmstore['store'] ." = ". $string ."<br />\n"; unset($projects_array); //<---- OR you can reset it here. }?>[/code] Quote Link to comment Share on other sites More sharing options...
piznac Posted January 30, 2007 Author Share Posted January 30, 2007 pog_check Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted January 30, 2007 Share Posted January 30, 2007 show me a few lines that are above and below line 20. including line 20. EDIT: i almost forgot! change this:[code]$projects_array[] = $row['pog_type'];[/code]to this:[code]$projects_array[] = $row_store['pog_type'];[/code] Quote Link to comment Share on other sites More sharing options...
piznac Posted January 30, 2007 Author Share Posted January 30, 2007 well I tried something there,. but changed it back. Also it is now working but not display the "pog_types" just the commas. EDITYeah I just changed that but still the samethis is what I have:[code]<?php require_once('../../Connections/conner.php'); $dm = $_GET['dm']; mysql_select_db($database_conner, $conner); $query_dmstore = "SELECT * FROM dmrmst"; $dmstore = mysql_query($query_dmstore, $conner) or die(mysql_error()); $totalRows_dmstore = mysql_num_rows($dmstore); echo "Total number of stores: ". $totalRows_dmstore ."<br />\n"; while($row_dmstore = mysql_fetch_array($dmstore)){ $query_store = "SELECT * FROM pog_check WHERE storenum = ". $row_dmstore['store'] .""; $store = mysql_query($query_store, $conner) or die(mysql_error()); $projects_array = array(); //<--- you can reset it here while($row_store = mysql_fetch_array($store)){ $projects_array[] = $row_store['pog_type']; } $string = implode(", ", $projects_array); echo "Store#". $row_dmstore['store'] ." = ". $string ."<br />\n"; unset($projects_array); //<---- OR you can reset it here. }?>[/code] Quote Link to comment Share on other sites More sharing options...
piznac Posted January 30, 2007 Author Share Posted January 30, 2007 Ok Im a dummy,.. lol ;D[code]$projects_array[] = $row_store['pog_type'];[/code]the colum name is pogtype not pog_typeThanks for all the help!!!!! Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted January 30, 2007 Share Posted January 30, 2007 did it work? if it did i'm glad i could get you squared away bro! ;D Quote Link to comment Share on other sites More sharing options...
piznac Posted January 30, 2007 Author Share Posted January 30, 2007 Oh yeah it worked,.. again thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.