Woodburn2006 Posted August 31, 2006 Share Posted August 31, 2006 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? Link to comment https://forums.phpfreaks.com/topic/19243-sql-in-a-function/ Share on other sites More sharing options...
techiefreak05 Posted August 31, 2006 Share Posted August 31, 2006 yes. heres a function that uses SQL code.. i use this on my site[code]<?phpfunction 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] Link to comment https://forums.phpfreaks.com/topic/19243-sql-in-a-function/#findComment-83342 Share on other sites More sharing options...
techiefreak05 Posted August 31, 2006 Share Posted August 31, 2006 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]<?phpinclude("file.php");?>[/code]at the top of the page u wish to use the functon. "file.php" is the filename that has the function Link to comment https://forums.phpfreaks.com/topic/19243-sql-in-a-function/#findComment-83346 Share on other sites More sharing options...
Woodburn2006 Posted August 31, 2006 Author Share Posted August 31, 2006 ok, cool thanks alot Link to comment https://forums.phpfreaks.com/topic/19243-sql-in-a-function/#findComment-83351 Share on other sites More sharing options...
techiefreak05 Posted August 31, 2006 Share Posted August 31, 2006 yep. np. if you need any help understading it more.. email me: [email protected] .. or IM me Link to comment https://forums.phpfreaks.com/topic/19243-sql-in-a-function/#findComment-83356 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.