Old 06-06-2005   #1 (permalink)
Registered User
 
Space Cowboy's Avatar
 
Join Date: May 2005
Location: England (South)
Posts: 40

Selecting from table

Ok im back again, im trying to make a script select a value from "Race" in my SQL database when given the username. I've bein trying to work it out for my self but so far im useless with SQL Querys
Code:
//SQL Querys
$sql = "SELECT * FROM $login_table WHERE username = '$username' AND Race";
Will ^^^ That code select the Race from the table givven the Username!

Then last bit here i want to make it output something Like this, where if the race = human it tells flash race is o and sends the race back to flash!
Code:
IF $Race=Human 

echo "checkrace=good"; 
echo "race=$race";
else

echo "checkrace=bad";
Space Cowboy is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-06-2005   #2 (permalink)
Invicible Snake
 
ParaSnake's Avatar
 
Join Date: Sep 2004
Location: Ho Chi Minh City,Vietnam
Posts: 668

Send a message via MSN to ParaSnake Send a message via Yahoo to ParaSnake
In fact,i dont understand what u are talking about SCB
Could u make it clearer,so that i can help u
__________________
ParaSnake is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-06-2005   #3 (permalink)
Registered User
 
Space Cowboy's Avatar
 
Join Date: May 2005
Location: England (South)
Posts: 40

OK sorry bout that iv bein working on this and if created this script
Code:
<?php
//Database Connectivity Variables//
$DBhost = "localhost";
$DBuser = "joj_test";
$DBpass = "test";
$db_name = "joj_stargate";
$login_table = "Finnal_Users"; 
//Create a connection to the MySQL Database//
$connection = @mysql_connect($DBhost,$DBuser,$DBpass) or die("Couldn't Connect.");
$db = @mysql_select_db($db_name, $connection) or die("Sorry, I could not select the requested Database ");
$query = "SELECT * FROM $login_table WHERE Username = '$username'";
    $result = mysql_query($query);
    
    while($row = mysql_fetch_array($result)){
		$Race = $row["Race"];
echo 'status=$Race';
exit;
}
?>
What i want it do do its fetch the race from the SQL table so if say user X loges in then runs this script the php searched for user X's Race then displays the race! The script iv got above doesnt seam to work right all i get in my output value is "$race" and no "Human" Which is what shoud come out for that user!

Im finding this hard to explain so i've uploaded a picture i want to loadinto flash useing echo the race of a user so i tried the above script but when i tested it instead of getting "Asgard" in the status bar i got "$Race" SO im guessing iv done something wrong!
Attached Thumbnails
selecting-table-sammple.jpg  
__________________
Space Cowboy

Thanks for all the help here guys!

Last edited by Space Cowboy; 06-06-2005 at 01:29 PM.
Space Cowboy is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-06-2005   #4 (permalink)
Invicible Snake
 
ParaSnake's Avatar
 
Join Date: Sep 2004
Location: Ho Chi Minh City,Vietnam
Posts: 668

Send a message via MSN to ParaSnake Send a message via Yahoo to ParaSnake
Ur nice pic says it all
so what u want is to do a mini function that will show the user`s race each time he/she logged in,rite?
PHP Code:
//assume that X has logged in and his username is store in $logged_username
//user is a table that store ur user`s informations
$a=mysql_query("SELECT * FROM user WHERE username='".$logged_username."' ")or die("problem with db");
//fetch the $a
$user_info=mysql_fetch_assoc($a);
//give the $race the user`s race value
$race=$user_info["race"];
//output it
echo $race
That is what u have to to,thx God that i still remember PHP`s structure,i almost forgot it :P
__________________
ParaSnake is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-06-2005   #5 (permalink)
Invicible Snake
 
ParaSnake's Avatar
 
Join Date: Sep 2004
Location: Ho Chi Minh City,Vietnam
Posts: 668

Send a message via MSN to ParaSnake Send a message via Yahoo to ParaSnake
I read through ur codes and i realized that u have sth wrong with ur syntax

this is wrong:
PHP Code:
$query "SELECT * FROM $login_table WHERE Username = '$username'"
and this is right:
PHP Code:
$query="SELECT * FROM $login_table WHERE username = '".$username."' "
That`s why ur script doesnt work

And after that i suggest u should recheck the username using "mysql_num_rows" to make sure its is a legal username
__________________
ParaSnake is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-06-2005   #6 (permalink)
Registered User
 
Space Cowboy's Avatar
 
Join Date: May 2005
Location: England (South)
Posts: 40

I changed a few things around but the script works very nicely again i thank you for you're help here!

Edit im using the first script you suggested and its running perfectly!
__________________
Space Cowboy

Thanks for all the help here guys!
Space Cowboy is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Closed Thread

Thread Tools
Display Modes

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Alternating table rows BlodoPKNZ HTML / PHP / ASP / JS 2 10-24-2004 05:12 PM
Going crazy.. text in a table... Runecaster HTML / PHP / ASP / JS 14 08-14-2004 08:31 AM
Scrollbar in a table? malboroman HTML / PHP / ASP / JS 17 12-23-2003 02:14 AM


All times are GMT +1. The time now is 09:44 PM.
Content Relevant URLs by vBSEO 3.2.0

Design & Content © BioRUST 2008 :: PRIVACY STATEMENT :: LEGAL INFORMATION :: ADVERTISING MEDIA KIT