NameSilo

Displaying Stuff With MySQL - Please Help

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch

Swefx

Established Member
Impact
2
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".

I'm quite new to MySQL so I dont know what to do.
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
0
Close
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;
}
 
0
Close
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 :tu:
 
0
Close
BillyConnite said:
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 :tu:
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:
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! :lol:
 
0
Close
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back