NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Displaying Stuff With MySQL - Please Help

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-14-2006, 04:56 AM THREAD STARTER               #1 (permalink)
NamePros Regular
Join Date: Jan 2006
Posts: 238
Swefx will become famous soon enoughSwefx will become famous soon enoughSwefx will become famous soon enough
 



Displaying Stuff With MySQL - Please Help


Ok so here's the code:

Code:
<?php
// The MySQL info, edit these
$host = "myhost"; // the database location. if you dont know it, leave it as it is
$dbuser = "myuser"; // the database username
$dbpass = "mypass"; // the databases user's pass
$dbname = "voting"; // the name of the database

// The actual connection. DO NOT EDIT THESE
mysql_connect("$host","$dbuser","$dbpass"); // Using the variables stated above

$display = ("SELECT challenger FROM battle");
echo $display;
?>
The problem is that instead of displaying the data it display "SELECT challenger FROM battle".
????: NamePros.com http://www.namepros.com/programming/197174-displaying-stuff-with-mysql-please-help.html

I'm quite new to MySQL so I dont know what to do.
Swefx is offline  
Old 05-14-2006, 06:16 AM   #2 (permalink)
Senior Member
 
Shorty's Avatar
Join Date: Sep 2005
Location: England
Posts: 1,034
Shorty is just really niceShorty is just really niceShorty is just really niceShorty is just really nice
 



Read my article on database queries:
http://www.goarticles.com/cgi-bin/showa.cgi?C=188575

Shorty is offline  
Old 05-14-2006, 06:33 AM   #3 (permalink)
NamePros Member
Join Date: Apr 2006
Location: Central PA
Posts: 101
NonProphet is on a distinguished road
 



theres more efficient ways to do it, but you can try this.
Code:
mysql_connect("$host","$dbuser","$dbpass");
mysql_select_db($dbname);
$display = "SELECT challenger FROM battle";
$result = mysql_query($display) or die(mysql_error());
while($row = mysql_fetch_assoc($result))
{
    $stuff = $row['challenger'];
     echo $stuff;
}
NonProphet is offline  
Old 05-14-2006, 07:44 AM   #4 (permalink)
 
BillyConnite's Avatar
Join Date: Jul 2005
Location: Coffs H, Australia
Posts: 3,456
BillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond repute
 


Wildlife Parkinson's Disease Parkinson's Disease
Furthering what NonProphet said:

Your code Swefx, simply echos a MySQL query, but first you need to run that query by MySQL, then MySQL will send back data from that query, in the form of an array (or a few other choices).

NonProphet's code should work fine
BillyConnite is offline  
Old 05-14-2006, 01:54 PM   #5 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice
 



Originally Posted by BillyConnite
Furthering what NonProphet said:

Your code Swefx, simply echos a MySQL query, but first you need to run that query by MySQL, then MySQL will send back data from that query, in the form of an array (or a few other choices).
????: NamePros.com http://www.namepros.com/showthread.php?t=197174

NonProphet's code should work fine
In your code $display will be either "true" or "false" depending on whether or not the mysql query worked or not.

You could do this with what you have:
PHP Code:
if($display){
  
// the mysql query worked:
  
while($row mysql_fetch_array($display)){
    echo 
$row['name_of_field_you_want_to_display'];
  }
}
else{
  
// the mysql query didn't work
  
echo "Something Wrong!<br />".mysql_error();

and there you have a simple error check as well!
PoorDoggie is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 11:38 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger