Jump to content

Archived

This topic is now archived and is closed to further replies.

Woodburn2006

SQL in a function

Recommended Posts

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?

Share this post


Link to post
Share on other sites
yes. heres a function that uses SQL code.. i use this on my site

[code]
<?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>";

}
}
?>
[/code]

Share this post


Link to post
Share on other sites
oh, and to call the function, put this on any page you want to use the function on:

[code]<?php yourInfo() ?>[/code]

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

at the top of the page u wish to use the functon. "file.php" is the filename that has the function

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.