Guest Posted November 6, 2010 Share Posted November 6, 2010 How do I got about outputing one row that can only hold one value? Any reason why the function below doesn't work? <?php include "database.php"; session_start(); $name = $_session['outname']; function output_wins(){ $sql = 'SELECT * FROM account_info WHERE username ="' . $name .'"'; $result = mysql_query($sql); $wins = mysql_fetch_array($result); echo $wins['win']; } output_wins(); ?> Is there an easier way I can output this one row? Link to comment https://forums.phpfreaks.com/topic/217956-output-a-row/ Share on other sites More sharing options...
litebearer Posted November 6, 2010 Share Posted November 6, 2010 Variables do NOT automatically pass to functions. Try... $name = $_session['outname']; function output_wins($name){ $sql = "SELECT * FROM account_info WHERE username = '$name'"; $result = mysql_query($sql); $wins = mysql_fetch_array($result); return $wins['win']; } echo output_wins($name); Link to comment https://forums.phpfreaks.com/topic/217956-output-a-row/#findComment-1131193 Share on other sites More sharing options...
Guest Posted November 6, 2010 Share Posted November 6, 2010 Ehh, it seems to work but it's not outputting anything. It's blank. Link to comment https://forums.phpfreaks.com/topic/217956-output-a-row/#findComment-1131196 Share on other sites More sharing options...
Guest Posted November 6, 2010 Share Posted November 6, 2010 Ah, here's the error: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Link to comment https://forums.phpfreaks.com/topic/217956-output-a-row/#findComment-1131198 Share on other sites More sharing options...
BlueSkyIS Posted November 7, 2010 Share Posted November 7, 2010 change the mysql_query line to this: $result = mysql_query($sql) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/217956-output-a-row/#findComment-1131224 Share on other sites More sharing options...
Guest Posted November 7, 2010 Share Posted November 7, 2010 change the mysql_query line to this: $result = mysql_query($sql) or die(mysql_error()); I did and this is the error: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Link to comment https://forums.phpfreaks.com/topic/217956-output-a-row/#findComment-1131227 Share on other sites More sharing options...
BlueSkyIS Posted November 7, 2010 Share Posted November 7, 2010 can you post your latest code? Link to comment https://forums.phpfreaks.com/topic/217956-output-a-row/#findComment-1131228 Share on other sites More sharing options...
Guest Posted November 7, 2010 Share Posted November 7, 2010 <?php include "database.php"; session_start(); $name = $_session['outname']; function output_wins($name){ $sql = "SELECT * FROM account_info WHERE username = '$name'"; $result = mysql_query($sql) or die(mysql_error()); $wins = mysql_fetch_array($result); return $wins['win']; } ?> Link to comment https://forums.phpfreaks.com/topic/217956-output-a-row/#findComment-1131231 Share on other sites More sharing options...
BlueSkyIS Posted November 7, 2010 Share Posted November 7, 2010 mysql_fetch_array(): supplied argument is not a valid MySQL result resource on line 8, correct? I guess we need to look at the sql. try this or something similar: function output_wins($name){ $sql = "SELECT * FROM account_info WHERE username = '$name'"; echo "sql: $sql <br />"; $result = mysql_query($sql) or die(mysql_error()); echo "result: ".$result."<br />"; $wins = mysql_fetch_array($result); echo "after mysql_fetch_array <br />"; return $wins['win']; } Link to comment https://forums.phpfreaks.com/topic/217956-output-a-row/#findComment-1131234 Share on other sites More sharing options...
Guest Posted November 7, 2010 Share Posted November 7, 2010 Edit: got this: sql: SELECT * FROM account_info WHERE username = "tony" result: Resource id #3 after mysql_fetch_array 0 Link to comment https://forums.phpfreaks.com/topic/217956-output-a-row/#findComment-1131236 Share on other sites More sharing options...
Guest Posted November 7, 2010 Share Posted November 7, 2010 Everything is working great now! I figured out what happen! Thanks! Link to comment https://forums.phpfreaks.com/topic/217956-output-a-row/#findComment-1131237 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.