A MySQL Query that Eludes Me...

A

Anonymous

Guest
Hi, I'm a total newb when it comes to coding something in an HTML document. What I need is something that can be viewed in a table. I'm running a CS server with WC3FT on it. IT uses experience, which is saved on a MySQL table in a database. What I want to do is put the info for ME ONLY, in my profile for my clan. I would like it to automatically change when I gain XP and it saves. If you don't understand what I'm saying, or might want to see what it'd look like, here's the link. I've heard it was a select query, but that's about all I've found out in about a weeks time searching for it. :sad:

My Profile

Thanks for all the help!

-f1del1ty
 
Well your post didn't help me much. someone else at another forum had to help me. But maybe you can help me here...this is my query for what I need.

SELECT xp
FROM `war3users`
WHERE playername='f1del1ty.oXi^Deagle' AND race = '1'

What I don't understand is how to make this a php command for my site. I want it to be that query, and show the XP on my site. How do I do that? here's the site

http://www.teamoxi.ath.cx/f1del1ty.php

Thanks.
 
in short:
yo need to use str mysql_query( str query, srt conn)
the long way:
read up on this
make sure that you understand how to use it
also read up on the see also sections, mainly:
mysql_connect()
mysql_select_db()
msql_fetch_array()
in that order, actually i'd read mysql_connect first, then query and then the rest...
Anyways your code would look something like this:
Code:
<?php
$conn=mysql_connect('host', 'user', 'pass') or die('could not connect'); //establish connection
$result=mysql_query("SELECT xp FROM war3users WHERE playername=f1del1ty.oXi^Deagle AND race = 1") or die('could not execute the query'); //run query
echo $result; //now do whatever with results
?>
 
Thanks Alex, but one more question..

If I did that whole $result thing, and closed the php stuff (the ?>), could I still use $result in my other stuff? Or should I just echo my table in php and use it like that?

BTW II'm using that code of yours and it's giving me the query error. What am I doing wrong? Here's the code I have..

Code:
<html> 
<head> 
</head> 
<body> 
<?php 
$conn=mysql_connect('localhost', 'user', '*******') or die('could not connect'); //establish connection 
$result=mysql_query("'SELECT xp FROM 'amx.war3users' WHERE playername = 'f1del1ty.oXi^Deagle' AND race = '1', $conn") or die('could not execute the query'); //run query 
echo $result; //now do whatever with results 
?> 
</body> 
</html>
 
The error he has ' Could not execute the query'. He set it up so it's like that. =X
 
die('could not execute the query'); replace with die(mysql_error());


That'lll give you full details.

Andrew
 
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''SELECT xp FROM 'amx.war3users' WHERE playername='f1del1ty.oXi'

Is the error I get. And for some reason the query doesn't work in MySQL anymore.

I fiddled around with it and got to this:

Resource id #3

My code is

Code:
<html> 
<head> 
</head> 
<body> 
<?php 
$conn=mysql_connect('localhost', 'amxuser', 'pass') or die('could not connect'); //establish connection 
$result=mysql_query ("SELECT xp FROM amx.war3users WHERE playername='f1del1ty.oXi' AND race=1", $conn) or die(mysql_error()); //run query 
echo $result; //now do whatever with results 
?> 
</body> 
</html>
 
I got it working. Now I'm working on a search query that will find my XP, and all my skill lvls. This is the code for my forms that I'm using:

Code:
<h3><u>Search By Player Name</u></h3>
<form method="post" action="getxp.php">
Player Name (What your last known name was):<br /><input name="name" type="text" size="30" maxlength="40" /><br />
<input type="submit" value="Send" /> <input type="reset" value="Reset" />
<br>
<br>
<br>
OR
<br>
<br>
<h3><u>Search By STEAM ID</u></h3>
<form method="post" action="getxp.php">
Player ID (STEAM_*:***** Format):<br /><input name="id" type="text" size="30" maxlength="40" /><br />
<input type="submit" value="Send" /> <input type="reset" value="Reset" />

Is it possible to make it so that there are two different forms, looking for the SAME DATA, but using different variables? Like in my example, I'm searching for all my XP and such, but I'm using either Playername or playerid to reach that. How might I go about that? Must they be two seperate .php files? Thanks.

The query that works for my select query was

Code:
<?php
$conn=mysql_connect('localhost', 'amxuser', '002003880') or die('could not connect'); //establish connection
$query = "SELECT playername, xp, race, skill1, skill2, skill3, skill4 FROM amx.war3users WHERE playername='f1del1ty.oXi' AND race='1'"; 
$results = @mysql_query($query); 
$result = mysql_fetch_array($results); // grabs the row and chops it up into an array where the 
//column names from your MySQL table are the array keys 

$playername = $result['playername']; // the word inside the brackets is the exact name of your MySQL column 
$xp = $result['xp']; 
$race = $result['race']; 
$skill1 = $result['skill1']; 
$skill2 = $result['skill2'];
$skill3 = $result['skill3'];
$skill4 = $result['skill4'];

echo '<table width="30%" border="0"><tr>';
echo '<td align="left"><b>Race:</b> Undead Scourge</td>';
echo '<td align="right"><b>XP:</b> ' .$xp .'</td></tr>';
echo '</table>'; 
?>
 
Back
Top