newb Posted August 5, 2006 Share Posted August 5, 2006 [code]<?phpinclude "config.php";//create connection$connection = mysql_connect("$mysql_host", "$mysql_login", "$mysql_pass") or die ("Couldnt connect to the server.");//select database$db = mysql_select_db("$mysql_database",$connection) or die ("Couldnt select the database. ".mysql_error());$sql = mysql_query("SELECT id,data FROM `p16_blocks` WHERE ID IN (0,1,2) ORDER BY `id` ASC"); $row = mysql_fetch_assoc($sql);// STEP 1// html definitions - format results by row$midlink = $row[0];$footerlink = $row[1];$copyright = $row[2];echo $midlink;echo $footerlink;echo $copyright;?>[/code]wtf this query isnt running. not echoing the html data from the mysql table. pls help, my tables look like this: http://img205.imageshack.us/img205/7595/tableod4.jpg Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted August 5, 2006 Share Posted August 5, 2006 mysql_fetch_row if you want to use numeric index Quote Link to comment Share on other sites More sharing options...
beamerrox Posted August 5, 2006 Share Posted August 5, 2006 [code]<?phpinclude "config.php";//create connection$connection = mysql_connect("$mysql_host", "$mysql_login", "$mysql_pass") or die ("Couldnt connect to the server.");//select databasemysql_select_db("$mysql_database", $connection) or die ("Couldnt select the database. ".mysql_error());$sql = mysql_query("SELECT id,data FROM `p16_blocks` WHERE ID IN (0,1,2) ORDER BY `id` ASC", $connection);$row = mysql_fetch_assoc($sql);// STEP 1// html definitions - format results by row$midlink = $row[0];$footerlink = $row[1];$copyright = $row[2];echo $midlink;echo $footerlink;echo $copyright;?>[/code]deletion of the "$db = "and addition of a ", $connection to the query" Quote Link to comment Share on other sites More sharing options...
newb Posted August 5, 2006 Author Share Posted August 5, 2006 ok this following code works a little bit:[code]<?phpinclude "config.php";//create connection$connection = mysql_connect("$mysql_host", "$mysql_login", "$mysql_pass") or die ("Couldnt connect to the server.");//select databasemysql_select_db("$mysql_database", $connection) or die ("Couldnt select the database. ".mysql_error());$sql = mysql_query("SELECT id,data FROM `p16_blocks` WHERE ID IN (0,1,2) ORDER BY `id` ASC", $connection);$row = mysql_fetch_row($sql);// STEP 1// html definitions - format results by row$midlink = $row["0"];$footerlink = $row["1"];$copyright = $row["2"];echo "$midlink";echo "$footerlink";echo "$copyright"?>[/code]It generates this in HTML[code]0<p align='center' class='midheader'><a href='#'>home</a> • <a href='#'>affiliates</a> • <a href='#'>servers</a> • <a href='#'>contact</a></p>[/code]It doesnt generate the rest of the html blocks, just the $midlink and for some reason it generates a 0 as well. Quote Link to comment Share on other sites More sharing options...
beamerrox Posted August 5, 2006 Share Posted August 5, 2006 [code]// STEP 1// html definitions - format results by row$midlink = $row[0];$footerlink = $row[1];$copyright = $row[2];[/code]this work?if not,[code]echo $midlink;echo $footerlink;echo $copyright;[/code]may work Quote Link to comment Share on other sites More sharing options...
newb Posted August 5, 2006 Author Share Posted August 5, 2006 nope. same thing Quote Link to comment Share on other sites More sharing options...
trq Posted August 5, 2006 Share Posted August 5, 2006 Numeric indexes are NOT to be surrounded in quotes. So....[code=php:0]$midlink = $row["0"];[/code]Should really be....[code=php:0]$midlink = $row[0];[/code] Quote Link to comment Share on other sites More sharing options...
beamerrox Posted August 5, 2006 Share Posted August 5, 2006 rank may say guru, but you are far newer to php than me...read 2 posts up eh. Quote Link to comment Share on other sites More sharing options...
newb Posted August 5, 2006 Author Share Posted August 5, 2006 ok deletion of SELECT id got rid of the unwanted zero, but still the other html blocks arent showing up.[code]<?phpinclude "config.php";//create connection$connection = mysql_connect("$mysql_host", "$mysql_login", "$mysql_pass") or die ("Couldnt connect to the server.");//select databasemysql_select_db("$mysql_database", $connection) or die ("Couldnt select the database. ".mysql_error());$sql = mysql_query("SELECT data FROM `p16_blocks` WHERE ID IN (0,1,2) ORDER BY `id` ASC", $connection);$row = mysql_fetch_row($sql);// STEP 1// html definitions - format results by row$midlink = $row[0];$footerlink = $row[1];$copyright = $row[2];echo $midlink;echo $footerlink;echo $copyright;?>[/code]im stuck. :s Quote Link to comment Share on other sites More sharing options...
trq Posted August 5, 2006 Share Posted August 5, 2006 [quote]rank may say guru, but you are far newer to php than me...[/quote]We posted at the same time smart guy. Quote Link to comment Share on other sites More sharing options...
trq Posted August 5, 2006 Share Posted August 5, 2006 [quote]but still the other html blocks arent showing up.[/quote]The code your posting produces NO html. Your also only selecting from the [i]data[/i] field in your query. Quote Link to comment Share on other sites More sharing options...
newb Posted August 5, 2006 Author Share Posted August 5, 2006 uhh, the html data definitely have html code inside them. http://img205.imageshack.us/img205/7595/tableod4.jpg i posted the tables to even prove it. for some reason only one will show up... Quote Link to comment Share on other sites More sharing options...
trq Posted August 5, 2006 Share Posted August 5, 2006 Look at your query!!!! Quote Link to comment Share on other sites More sharing options...
newb Posted August 5, 2006 Author Share Posted August 5, 2006 [quote author=thorpe link=topic=103059.msg410039#msg410039 date=1154760900][quote]but still the other html blocks arent showing up.[/quote]The code your posting produces NO html. Your also only selecting from the [i]data[/i] field in your query.[/quote]thats the only field i need to select from. at the moment, i just want to grab data from the table and echo it into the page and for some reason, it fails to do that. Quote Link to comment Share on other sites More sharing options...
newb Posted August 5, 2006 Author Share Posted August 5, 2006 [quote author=thorpe link=topic=103059.msg410041#msg410041 date=1154761079]Look at your query!!!![/quote]what about it? Quote Link to comment Share on other sites More sharing options...
trq Posted August 5, 2006 Share Posted August 5, 2006 Ah... sorry. If you want more than one record you need to use a loop. eg;[code=php:0]while ($row = mysql_fetch_row($sql)) { $midlink = $row[0]; $footerlink = $row[1]; $copyright = $row[2]; echo $midlink; echo $footerlink; echo $copyright;}[/code] Quote Link to comment Share on other sites More sharing options...
newb Posted August 5, 2006 Author Share Posted August 5, 2006 [code]<?phpinclude "config.php";//create connection$connection = mysql_connect("$mysql_host", "$mysql_login", "$mysql_pass") or die ("Couldnt connect to the server.");//select databasemysql_select_db("$mysql_database", $connection) or die ("Couldnt select the database. ".mysql_error());$sql = mysql_query("SELECT data FROM `p16_blocks` WHERE ID IN (0,1,2) ORDER BY `id` ASC", $connection);$row = mysql_fetch_row($sql);// STEP 1// html definitions - format results by rowwhile ($row = $row = mysql_fetch_row($sql)) { $midlink = $row[0]; $footerlink = $row[1]; $copyright = $row[2]; echo $midlink; echo $footerlink; echo $copyright;}?>[/code]bah, ur code almost works thorpe, except $midlink doesnt show. the other two blocks generate though (footerlink and copyright)[code]<p align='center'>Home • Affiliates • Servers • Contact • Teams • Signup • Resources • Information • Schedule • Results • Forums • Captains<br /><p align='center'>Copyright 2006 © <b>p16draft.net</b>. All Rights Reserved.</p>[/code]thats what generates on the html page now Quote Link to comment Share on other sites More sharing options...
newb Posted August 5, 2006 Author Share Posted August 5, 2006 btw i tried while ($row = $row = $row nothing happened Quote Link to comment Share on other sites More sharing options...
xec Posted August 5, 2006 Share Posted August 5, 2006 'thats the only field i need to select from. at the moment, i just want to grab data from the table and echo it into the page and for some reason, it fails to do that.'------------boy, in your you have only selected one field and it will only give result in $row[0]... just add * instead of data, then $row[0],$row[1],$row[2] all will be working.. Quote Link to comment Share on other sites More sharing options...
trq Posted August 5, 2006 Share Posted August 5, 2006 [quote]bah, ur code almost works thorpe, except $midlink doesnt show. [/quote]Because (AS IVE SAID!!!) your only selecting one field! Quote Link to comment Share on other sites More sharing options...
newb Posted August 5, 2006 Author Share Posted August 5, 2006 [quote author=thorpe link=topic=103059.msg410051#msg410051 date=1154762107][quote]bah, ur code almost works thorpe, except $midlink doesnt show. [/quote]Because (AS IVE SAID!!!) your only selecting one field![/quote]and hows that a problem? i dont get it, which fields should i select :s Quote Link to comment Share on other sites More sharing options...
trq Posted August 5, 2006 Share Posted August 5, 2006 Which fields do you want? the table you showed us has the fileds [i]id, name, active[/i] and [i]data[/i]. Quote Link to comment Share on other sites More sharing options...
newb Posted August 5, 2006 Author Share Posted August 5, 2006 yeah i know, the only field that i needed at the moment was the data field, i was planning on utilizing the other fields later on. Quote Link to comment Share on other sites More sharing options...
trq Posted August 5, 2006 Share Posted August 5, 2006 Well then.... the only $row that will hoild a value is $row[0]. Quote Link to comment Share on other sites More sharing options...
newb Posted August 5, 2006 Author Share Posted August 5, 2006 ugh, i figured out the problem. [code]<?phpinclude "config.php";//create connection$connection = mysql_connect("$mysql_host", "$mysql_login", "$mysql_pass") or die ("Couldnt connect to the server.");//select databasemysql_select_db("$mysql_database", $connection) or die ("Couldnt select the database. ".mysql_error());$sql = mysql_query("SELECT data FROM `p16_blocks` WHERE id IN (0,1,2) ORDER BY `id` ASC", $connection);$row = mysql_fetch_row($sql);// STEP 1// html definitions - format results by rowwhile ($row = mysql_fetch_row($sql)) { $midlink = $row[0]; $footerlink = $row[1]; $copyright = $row[2]; echo $midlink; echo $footerlink; echo $copyright;}?>[/code]I needed to remove [code]$row = mysql_fetch_row($sql);[/code]. Fix:[code]<?phpinclude "config.php";//create connection$connection = mysql_connect("$mysql_host", "$mysql_login", "$mysql_pass") or die ("Couldnt connect to the server.");//select databasemysql_select_db("$mysql_database", $connection) or die ("Couldnt select the database. ".mysql_error());$sql = mysql_query("SELECT data FROM `p16_blocks` WHERE id IN (0,1,2) ORDER BY `id` ASC", $connection);// STEP 1// html definitions - format results by rowwhile ($row = mysql_fetch_row($sql)) { $midlink = $row[0]; $footerlink = $row[1]; $copyright = $row[2]; echo $midlink; echo $footerlink; echo $copyright;}?>[/code] 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.