| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| NamePros Regular | 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;
?>
I'm quite new to MySQL so I dont know what to do. |
| |
| | #3 (permalink) |
| NamePros Member | 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;
}
|
| |
| | #4 (permalink) |
![]() | 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
__________________ <?php if(1===1){ $computer="fine."; }else{ $computer="broken."; } echo "Your computer is ".$computer; ?> |
| |
| | #5 (permalink) | |
| Soon to be RICHdoggie! | Quote:
You could do this with what you have: PHP Code: | |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |