Jump to content

Archived

This topic is now archived and is closed to further replies.

Rick_Browne

Database Connection Not Working

Recommended Posts

Hi all,

I hope you can help me

I 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.....

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.