Dynadot โ€” .com Registration $8.99

Displaying Stuff With MySQL - Please Help

Spaceship Spaceship
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
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
0
•••
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
•••
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
•••
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
•••
Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back