Rick_Browne Posted June 5, 2006 Share Posted June 5, 2006 Hi all,I hope you can help meI use the following section of code to build a table of 50 by 50 squares- each square is populated with a name, its coordinates, and its type.[code] $db = mysql_connect("*****", "*****", "*****"); mysql_select_db("contacts",$db);for($down=0;$down<50;$down++) { echo "<tr>"; for($across=0;$across<50;$across++) { $id = "$down,$across"; $result = mysql_query("SELECT * FROM coordinates WHERE id=$id",$db); $myrow = mysql_fetch_array($result); $name = $myrow["name"]; $type = $myrow["type"]; ?><td Width="100" Height="100"> <table border="0" align="center"> <tr><td><center><?php printf("%s",$myrow["name"]) ?></center></td></tr> <tr><td nowrap><center><a href="?id=<?php echo $id?>">( <?php echo $id ?> )</a></center></td></tr> <tr><td><center><?php echo $type?></center></td></tr> </table> </td><?php } echo "</tr>"; }?>[/code]The table builds itself fine and enters in all the correct coordinates- but the name and type fields remain empty.As you can see I have tried a different method for both to try and find a solution but my php is a bit rusty these days :(Im sure its something simple ive missed..... Quote Link to comment https://forums.phpfreaks.com/topic/11242-database-connection-not-working/ Share on other sites More sharing options...
hiphoplsr Posted June 5, 2006 Share Posted June 5, 2006 yo rick, i think it might be as simple as this....is your select_db tag wrong? heres what i use:[code]mysql_connect(localhost,$username,$password);@mysql_select_db($database) or die( "Unable to select database");[/code][!--quoteo(post=380233:date=Jun 5 2006, 09:25 AM:name=Rick_Browne)--][div class=\'quotetop\']QUOTE(Rick_Browne @ Jun 5 2006, 09:25 AM) [snapback]380233[/snapback][/div][div class=\'quotemain\'][!--quotec--][code] $db = mysql_connect("*****", "*****", "*****"); mysql_select_db("contacts",$db);[/code]The table builds itself fine and enters in all the correct coordinates- but the name and type fields remain empty.As you can see I have tried a different method for both to try and find a solution but my php is a bit rusty these days :(Im sure its something simple ive missed.....[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/11242-database-connection-not-working/#findComment-42077 Share on other sites More sharing options...
.josh Posted June 5, 2006 Share Posted June 5, 2006 okay you have two loops $down and $across, which are numerical values. So you assign them in $id as $id='$down, $across';this makes $id a string type variable. so unless your id column is a string type, and it holds information as "12, 14""1,34"etc..then it is not going to select anything from the database. if you are trying to build a grid that has names/types in each square, based on your code up there, you have your db table setup wrong.you are going to have to setup several tables and link them (look into relational databases). also, I would suggest that you pull out all the information you need at one time, and then build the html table, instead of querying the database 2,500 times... Quote Link to comment https://forums.phpfreaks.com/topic/11242-database-connection-not-working/#findComment-42099 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.