Jump to content

output a row?


Guest

Recommended Posts

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

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

<?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

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

Archived

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

×
×
  • Create New...

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.