Jump to content


Photo

SQL in a function


  • Please log in to reply
4 replies to this topic

#1 Woodburn2006

Woodburn2006
  • Members
  • PipPipPip
  • Advanced Member
  • 214 posts

Posted 31 August 2006 - 08:50 AM

can you put sql queries in a function, whenever i have tries i cannot seem to get it to work.

is there anything specific that you need to do?

#2 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 31 August 2006 - 08:53 AM

yes. heres a function that uses SQL code.. i use this on my site

<?php
function yourInfo(){
$sql = "SELECT * FROM users WHERE username = '$_SESSION[username]' LIMIT 1";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<center><b>Getting Info for: " .$row[username]. "</b></center>";
echo "<b>First Name: <u>".$row['fname']."</u><p>";
echo "Username: <u>".$row['username']."</u><p>";
echo "zyPoints: <u>".$row['zypoints']."</u><p>";
echo "E-mail: <u>".$row['email']."</u><p></b>";
echo "<center><a href='editAccnt.php'>Edit Account</a></center>";

}
}
?>

Link shortener with advanced, detailed statistics:

http://tyny.us/

#3 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 31 August 2006 - 08:55 AM

oh, and to call the function, put this on any page you want to use the function on:

<?php yourInfo() ?>

if you in clude all your functions in a seperate file than what your displaying them in.. you have to put
<?php
include("file.php");
?>

at the top of the page u wish to use the functon. "file.php" is the filename that has the function
Link shortener with advanced, detailed statistics:

http://tyny.us/

#4 Woodburn2006

Woodburn2006
  • Members
  • PipPipPip
  • Advanced Member
  • 214 posts

Posted 31 August 2006 - 09:02 AM

ok, cool thanks alot

#5 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 31 August 2006 - 09:11 AM

yep. np. if you need any help understading it more.. email me: techiefreak05@gmail.com .. or IM me
Link shortener with advanced, detailed statistics:

http://tyny.us/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users