[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 05-14-2006, 03:56 AM   #1 (permalink)
NamePros Regular
 
Join Date: Jan 2006
Posts: 238
2.25 NP$ (Donate)

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".

I'm quite new to MySQL so I dont know what to do.
Swefx is offline  
Old 05-14-2006, 05:16 AM   #2 (permalink)
Senior Member
 
Shorty's Avatar
 
Join Date: Sep 2005
Location: England
Posts: 1,035
102.05 NP$ (Donate)

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, 05:33 AM   #3 (permalink)
NamePros Member
 
Join Date: Apr 2006
Location: Central PA
Posts: 98
0.00 NP$ (Donate)

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, 06:44 AM   #4 (permalink)
 
BillyConnite's Avatar
 
Join Date: Jul 2005
Location: Coffs H, Australia
Posts: 3,107
47.00 NP$ (Donate)

BillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant future

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
__________________
<?php if(1===1){ $computer="fine."; }else{ $computer="broken."; } echo "Your computer is ".$computer; ?>
BillyConnite is offline  
Old 05-14-2006, 12:54 PM   #5 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
 
Join Date: Jan 2005
Location: UK
Posts: 2,390
316.50 NP$ (Donate)

PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice


Quote:
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).

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 12:06 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85