Jump to content


Photo

Database Connection Not Working


  • Please log in to reply
2 replies to this topic

#1 Rick_Browne

Rick_Browne
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 05 June 2006 - 03:25 PM

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.


  $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>";
    
}

?>

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

#2 hiphoplsr

hiphoplsr
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 05 June 2006 - 05:02 PM

yo rick, i think it might be as simple as this....

is your select_db tag wrong? heres what i use:

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

[!--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) View Post[/div][div class=\'quotemain\'][!--quotec--]


  $db = mysql_connect("*****", "*****", "*****");
  mysql_select_db("contacts",$db);


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]

#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 05 June 2006 - 06:16 PM

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...
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users