Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Guys newbie help please..... 1

Status
Not open for further replies.

coldfused

Technical User
Joined
Jan 27, 2001
Messages
2,442
Location
US
Ok guys I am just diving into the php sql thing so your patience is appreciated.

Ok so I am trying to connect to a database called "Townhomes". I can make the connection to the database fine, but it is not pulling out the table. I spoke with my host they said there is no remote access restrictions on their side, I should be able to connect and retreive the data. So here is my code:

Code:
<?php

  // Connect to the database server  
  $dbcnx = @mysql_connect(&quot;orlandomediasolutions.com&quot;, &quot;dbname&quot;, &quot;pass&quot;);  
  if (!$dbcnx) {    
  echo( &quot;<P>Unable to connect to the &quot; .          
  &quot;database server at this time.</P>&quot; );  exit(); }

  // Select the Townhomes database  
  if (! @mysql_select_db(&quot;dbname&quot;) ) {    
  echo( &quot;<P>Unable to locate the dbname &quot; .          
  &quot;database at this time.</P>&quot; ); exit();  }

?>
<P> Here are all the Townhomes in our database: </P>

<?php    // Request the Name of all the Townhomes  
$result = mysql_query(            
&quot;SELECT Name FROM Townhomes&quot;);  
if (!$result) {    
echo(&quot;<P>Error performing query: &quot; .         
mysql_error() . &quot;</P>&quot;);    
exit();  }

  // Display the Name of each Townhome in a paragraph  
  while ( $row = mysql_fetch_array($result) ) {    
  echo(&quot;<P>&quot; . $row[&quot;Name&quot;] . &quot;</P>&quot;);  }

?>

So i'm hanging up at // Select the Townhomes database ..

Any ideas?

---------------------------------------------
 
Nevermind.

Got it worked out. Was trying to connect to the table itself instead of the actual database.


Go figure.....

orlandomediasolutions.com/test/index.php

Ok so a question, I need to find a tutorial on this. When I pull the townhome names from the table I want them to show up as links. That way a user can click on them and display the info about that townhome. Which will be the rest of the information pulled from the same database.

I can work that out I think, just need some direction.


Any have enough patience to help me thru this?




---------------------------------------------
 
what is the error ur getting?
I mean is ur script getting connected to the server but not able to select the database or is it not able to fetch record from the table?

is ur username and password for the MySQL server proper?




--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
How do I make this show up as a link? The name of eachh townhome displayed?

// Display the Name of each Townhome in a paragraph
while ( $row = mysql_fetch_array($result) ) {
echo(&quot;<P>&quot; . $row[&quot;Name&quot;] . &quot;</P>&quot;); }



---------------------------------------------
 
Code:
  while ( $row = mysql_fetch_array($result) ) {    
echo &quot;<p><a href=displayinfo.php?id=$row[id]>$row[name]</a></p>&quot; ;
in displayinfo.php (or it can be a same script) u can again query DB to fetch the detailed info.
$sql = &quot;SELECT info FROM tablename where id=$_GET['id']&quot; ;
etc..

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top