dropfaith Posted November 25, 2009 Share Posted November 25, 2009 i got this all working but the headings arent echoing to the browserupon checking source for the page <h3></h3> are echoed out but the data is not any ideas why? <?php include("admin/db_connect.inc.php"); $connection = mysql_connect(HOST, DBUSER, PASS) or die('Could not connect !<br />Please contact the site\'s administrator.'); $db = mysql_select_db(DB) or die('Could not connect to database !<br />Please contact the site\'s administrator.'); // get the info from the db $sql = "SELECT * FROM live"; $result = mysql_query($sql, $connection) or trigger_error("SQL", E_USER_ERROR); $sortedlist = array(); while ($list = mysql_fetch_assoc($result)) { $sortedlist[$list['Type']][] = $list; } foreach($sortedlist as $list) { //echo "<pre>"; print_r($list); echo "</pre>"; echo "<h3>{$list['Type']}</h3>\n"; echo "<ul>\n"; foreach($list as $entry) { //echo "<pre>"; print_r($entry); echo "</pre>"; echo "<li>"; if(empty($entry['Link'])) echo $entry['Name']; else echo "<a href=\"{$entry['Link']}\">{$entry['Name']}</a>"; echo "{$entry['Venue']} {$entry['Year']}"; echo "</li>\n"; } echo "</ul>\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/182855-h3-wont-echo-out/ Share on other sites More sharing options...
Goldeneye Posted November 25, 2009 Share Posted November 25, 2009 I'm not sure, but it looks like $sortedlist is a two-dimensional array. And you're just echoing the array in the Type-dimension. It looks like you have to do: echo "<h3>{$list['Type'][0]}</h3>\n"; (or whatever array-key you're trying to echo) instead of: echo "<h3>{$list['Type']}</h3>\n"; Quote Link to comment https://forums.phpfreaks.com/topic/182855-h3-wont-echo-out/#findComment-965145 Share on other sites More sharing options...
dropfaith Posted November 25, 2009 Author Share Posted November 25, 2009 nope still the same thing i had with that. it need to echo the type thru a loop like say theres 20 results in 5 groups H3 group 1 somecrapi more H3 group 2 so on and so forth http://dropfaith.freei.me/liveperformance.php is a test site for now if you look its grouping them correctly but the headers wont echo out which confuses me Quote Link to comment https://forums.phpfreaks.com/topic/182855-h3-wont-echo-out/#findComment-965152 Share on other sites More sharing options...
Goldeneye Posted November 25, 2009 Share Posted November 25, 2009 Uncomment "//echo "<pre>"; print_r($list); echo "</pre>";" and post the array here. Quote Link to comment https://forums.phpfreaks.com/topic/182855-h3-wont-echo-out/#findComment-965179 Share on other sites More sharing options...
dropfaith Posted November 25, 2009 Author Share Posted November 25, 2009 Array ( [0] => Array ( [id] => 2 [Year] => ert [Name] => ert [Link] => rt [Type] => ert [Venue] => ert ) ) http://dropfaith.freei.me/liveperformance.php there the display Quote Link to comment https://forums.phpfreaks.com/topic/182855-h3-wont-echo-out/#findComment-965226 Share on other sites More sharing options...
dropfaith Posted November 25, 2009 Author Share Posted November 25, 2009 somewhere in this chunk of code its messed up and wont echo the text of the h3 everything else works fine {$list['Type'][0]} is rhe olny thing not being echoed wonders $sortedlist = array(); while ($list = mysql_fetch_assoc($result)) { $sortedlist[$list['Type']][] = $list; } foreach($sortedlist as $list) { //echo "<pre>"; print_r($list); echo "</pre>"; echo "<h3>{$list['Type'][0]}</h3>\n"; echo "<ul>\n"; Quote Link to comment https://forums.phpfreaks.com/topic/182855-h3-wont-echo-out/#findComment-965241 Share on other sites More sharing options...
Cosizzle Posted November 25, 2009 Share Posted November 25, 2009 $sortedlist = array(); while ($list = mysql_fetch_assoc($result)) { $sortedlist[$list['Type']][] = $list; } foreach($sortedlist as $list) { //echo "<pre>"; print_r($list); echo "</pre>"; echo "<h3>$list['Type'][0]</h3>\n"; echo "<ul>\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/182855-h3-wont-echo-out/#findComment-965244 Share on other sites More sharing options...
dropfaith Posted November 25, 2009 Author Share Posted November 25, 2009 that made the entire page go white Quote Link to comment https://forums.phpfreaks.com/topic/182855-h3-wont-echo-out/#findComment-965250 Share on other sites More sharing options...
dropfaith Posted November 25, 2009 Author Share Posted November 25, 2009 is the full code <?php error_reporting(E_ALL); include("admin/db_connect.inc.php"); $connection = mysql_connect(HOST, DBUSER, PASS) or die('Could not connect !<br />Please contact the site\'s administrator.'); $db = mysql_select_db(DB) or die('Could not connect to database !<br />Please contact the site\'s administrator.'); // get the info from the db $sql = "SELECT * FROM live"; $result = mysql_query($sql, $connection) or trigger_error("SQL", E_USER_ERROR); $sortedlist = array(); while ($list = mysql_fetch_assoc($result)) { $sortedlist[$list['Type']][] = $list; } foreach($sortedlist as $list) { //echo "<pre>"; print_r($list); echo "</pre>"; echo "<h3>{$list['Type'][0]}</h3>\n"; echo "<ul>\n"; foreach($list as $entry) { //echo "<pre>"; print_r($entry); echo "</pre>"; echo "<li>"; if(empty($entry['Link'])) echo $entry['Name']; else echo "<a href=\"{$entry['Link']}\">{$entry['Name']}</a>"; echo "{$entry['Venue']} {$entry['Year']}"; echo "</li>\n"; } echo "</ul>\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/182855-h3-wont-echo-out/#findComment-965255 Share on other sites More sharing options...
dropfaith Posted November 25, 2009 Author Share Posted November 25, 2009 bump Quote Link to comment https://forums.phpfreaks.com/topic/182855-h3-wont-echo-out/#findComment-965580 Share on other sites More sharing options...
dropfaith Posted November 29, 2009 Author Share Posted November 29, 2009 http://dropfaith.freei.me/liveperformance.php wtf so im playing with this some more and tryed <?php $sortedlist = array(); while ($list = mysql_fetch_assoc($result)) { $sortedlist[$list['Type']][] = $list; } foreach($sortedlist as $list) { //echo "<pre>"; print_r($list); echo "</pre>"; echo "<h3>{$entry['Type']}</h3>\n"; echo "<ul>\n"; foreach($list as $entry) { //echo "<pre>"; print_r($entry); echo "</pre>"; echo "<li>"; if(empty($entry['Link'])) echo $entry['Name']; else echo "<a href=\"{$entry['Link']}\">{$entry['Name']}</a>"; echo "{$entry['Venue']} {$entry['Year']}{$entry['Type']}"; echo "</li>\n"; } echo "</ul>\n"; }?> which almost worked but its one off like one down the top list has no type and then they start with the top ones type over the second list set this is pissing me off its the only thing left on this site and i cant fiqure it out Quote Link to comment https://forums.phpfreaks.com/topic/182855-h3-wont-echo-out/#findComment-967513 Share on other sites More sharing options...
Cosizzle Posted November 29, 2009 Share Posted November 29, 2009 You need to break this apart and debug it in steps. 1st print your arrays and see what they're showing. echo '<pre>'; print_r($sortedlist); echo '</pre>'; and echo '<pre>'; print_r($entry); echo '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/182855-h3-wont-echo-out/#findComment-967641 Share on other sites More sharing options...
dropfaith Posted November 30, 2009 Author Share Posted November 30, 2009 http://dropfaith.freei.me/liveperformance.php first one is entry second one is sortedlisthave them both echoed out Quote Link to comment https://forums.phpfreaks.com/topic/182855-h3-wont-echo-out/#findComment-967898 Share on other sites More sharing options...
Alex Posted November 30, 2009 Share Posted November 30, 2009 Judging by the print_r of the $list array you should be using $list[0]['Type'] not $list['Type'][0]. Quote Link to comment https://forums.phpfreaks.com/topic/182855-h3-wont-echo-out/#findComment-967900 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.