Languages :: PHP :: Problem With Query |
|||
| By: PHP newbee |
Date: 08/06/2003 00:00:00 |
Points: 50 | Status: Answered Quality : Excellent |
|
I have just started working with mySQL and I am trying to get my form to gather a URL of an avatar and homepage from the same row, given that we know the username. mysql_query("Select * from oldschool where username='$username' AND avatar='$avatar' AND homepage='$homepage'"); When I print $avatar and $homepage, I get two blank spots. Does anyone know what I'm doing wrong? |
|||
| By: VGR | Date: 08/06/2003 20:17:00 | Type : Comment |
|
| nothing wrong. Just that you didn't pass non-empty values in $avatar or in $homepage... what you want is to query the database with three arguments ? Or isn't it rather this that you want ?!? mysql_query("Select avatar, homepage from oldschool where username='$username';"); |
|||
| By: PHP newbee | Date: 08/06/2003 20:28:00 | Type : Comment |
|
| no what i'm trying to do is dump them in just variables. That was just an example, here is what I actually did: mysql_connect ("mysql01.powweb.com", "momonja", "duckmonkey81188"); mysql_select_db ("gamingd"); mysql_query("Select * from oldschool where username='$alreadyUsername' AND level='$checkLevel' AND experience='$checkExperience' AND gil='$checkGil' AND attack='$checkAttack' AND defense='$checkDefense' AND agility='$checkAgility' AND intelligence='$checkIntelligence' AND equipped='$checkEquipped' AND damage_min='$checkDMI' AND damage_max='$checkDMA'"); |
|||
| By: PHP newbee | Date: 08/06/2003 20:29:00 | Type : Comment |
|
| CRAP! i just put my pass down. uhhm... crap. ...help? |
|||
| By: PHP newbee | Date: 08/06/2003 20:30:00 | Type : Comment |
|
| oh well, time to go change pass ;) |
|||
| By: VGR | Date: 08/06/2003 21:28:00 | Type : Comment |
|
| isn't it more an UPDATE that you try to perform, rather than a SELECT that has no chance to work ? 1) are you trying to WRITE or READ from the table ? 2) what is your KEY to write (an ID, a Username...), ie the element being the key of the table operation |
|||
| By: TheFalklands | Date: 08/06/2003 21:32:00 | Type : Comment |
|
| what your sample does is fetching all columns of every raws that verifys ALL the criterions you gave (username, level, experience, gil, attack, defense, agility, intelligence.. and so on). you realize you dont gather these value for the username you gave ? you realize that ALL these criterions need to have a valid content before the query, and that they wont be changed by the query ? select syntax is : SELECT what i want to get back FROM the table i want WHERE these criterions are met maybe what you really want looks like "select level, experience, gil, attack, defense, agility, intelligence from oldschool where username=$alreadyUsername " |
|||
| By: VGR | Date: 08/06/2003 22:08:00 | Type : Comment |
|
| yes, that exactly what I suggested in the first comment to this Question, but apparently he's trying "to dump then in just variables", whatever this means :D |
|||
| By: PHP newbee | Date: 08/06/2003 22:31:00 | Type : Comment |
|
| Well, what I'm trying to do is take 'level' and put it in $level... experience -> $experience gil -> $gil and so on... |
|||
| By: TheFalklands | Date: 08/06/2003 22:53:00 | Type : Comment |
|
| mysql doc says : UPDATE tbl_name SET col_name1=expr1 [, col_name2=expr2, ...] [WHERE where_definition] [ORDER BY ...] [LIMIT #] so in you case it should looks like : update oldschool set level=$checkLevel,defense=... etc .... where username='$alreadyUsername'; |
|||
| By: VGR | Date: 08/06/2003 23:19:00 | Type : Comment |
|
| again, mistake it was indeed the first suggestion : mysql_query("Select avatar, homepage from oldschool where username='$username';"); in your case: mysql_connect ("mysql01.powweb.com", "momonja", "duckmonkey81188"); mysql_select_db ("gamingd"); $result=mysql_query("Select from oldschool where username='$alreadyUsername';) or die(mysql_error()); $res=mysql_fetch_array($result); $checkLevel=$res['Level']; $checkExperience=$res['experience']; $checkGil=$res['gil']; $checkAttack=$res['attack']; $checkDefense=$res['defense']; $checkAgility=$res['agility']; $checkIntelligence=$res['intelligence']; $checkEquipped=$res['equipped']; $checkDMI=$res['damage_min']; $checkDMA=$res['damage_max']; |
|||
| By: mattjp88 | Date: 09/06/2003 00:14:00 | Type : Comment |
|
| are you sure that you defined your variables, maybe hey are being passed by POST or GET. just a suggestion. -Matt |
|||
| By: digitaltree | Date: 09/06/2003 23:29:00 | Type : Comment |
|
| well, what about putting variables into {$variable} inside the mysql query instead of keeping them in '$variable'? |
|||
| By: PHP newbee | Date: 09/06/2003 23:42:00 | Type : Comment |
|
| well, he has it all done with VGR's last post. isn't it ok ? tried to cut, paste and check ? |
|||
| By: VGR | Date: 09/06/2003 23:45:00 | Type : Comment |
|
| digitalTree, what you suggest is for nothing ;-) {$variable} is the same as $variable it doesn't change anything here, where the problem is that string litterals have to be enclosed in single quotes in SQL ;-) |
|||
| By: Tyriel | Date: 10/06/2003 00:20:00 | Type : Comment |
|
| PHPnewbee, It appears to me as if you're slightly unsure about how to use SQL... you seem to have confused some of us about what it is, exactly, that you want to do. I'd be happy to take 5 minutes tonight and work with you live if you need help getting started with MySQL. Hit me up on ICQ #6854118 if you'd like a hand. |
|||
| By: jgallo | Date: 10/06/2003 07:59:00 | Type : Comment |
|
| Couldn't understand what you really want. You have the user name and want the avatar and homepage that are on the db? $result = mysql_query("Select * from oldschool where username='$username'"); $row = mysql_fetch_array($result); $avatar = $row["avatar"]; $homepage = $row["homepage"]; That's it What else do you want? |
|||
| By: VGR | Date: 10/06/2003 08:08:00 | Type : Comment |
|
| 1) 06/08/2003 03:17AM PDT 2) "no, I'm trying to dump..." |
|||
| By: jgallo | Date: 11/06/2003 20:13:00 | Type : Comment |
|
| Sure he is dumping variables, but he should know which variables does he have and what does he want, also what kind of data combinations on his database would return just the records he wants. Which are the keys? What does he want to be returned? |
|||
| By: PHP newbee | Date: 12/06/2003 06:57:00 | Type : Comment |
|
| I'm sorry I confused you guys.......... But all I'm trying to do is get a cell out of the table... nothing complicated. Let's just say I want to print a cell. How do I pin point it and all that, then print it? |
|||
| By: PHP newbee | Date: 12/06/2003 07:53:00 | Type : Comment |
|
| I found this: $query = "SELECT * FROM tablename ORDER BY thing DESC"; $result = MySql_Query($query); if (!$result) die("Error selecting query: ".MySql_Error()); while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { print "$line[cellname]"; } and it kinda ansewered my quesiton. But maybe you guys could answer this one, since there are still the 50 points remaining... How could I make it so I give the table a value, and it will look through a column to find that value. When it finds that value, it will put the contents of that row (that the certain value is held in) into an array. So I could call on different parts of the row by just saying $row[0], $row[1]... etc. |
|||
| By: VGR | Date: 12/06/2003 08:30:00 | Type : Answer |
|
| exactly as above, but with a first select containing $query = "SELECT * FROM tablename WHERE thecolumn='$thevaluesearched';"; |
|||
| By: VGR | Date: 12/06/2003 08:31:00 | Type : Comment |
|
| please note my first comment of Date: 06/08/2003 03:17AM PDT to which you answered "no" ;-) |
|||
| By: PHP newbee | Date: 12/06/2003 14:09:00 | Type : Comment |
|
| VGR = walking talking computer encyclopedia thanks and, keep it up VGR! |
|||
| By: VGR | Date: 12/06/2003 14:35:00 | Type : Comment |
|
| happy to see this problem solved, at last :D |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








