I am trying to retrieve like several different values from a table. I got it working, but it is actually only sending me the last value it calls. I have done several different things trying to call all my values, but it is not working. Here is what I have.
$infoChanger = $_GET['changer'];
$username = $_GET['user'];
$sql="SELECT * FROM Login_Info WHERE user='".$username."'";
$r = mysql_query($sql,$con);
$row = mysql_fetch_array($r);
if ($row[7] != "")
{
if ( $infoChanger == 1 ) {
echo $row['user'];
}
else if ( $infoChanger == 2 ) {
echo $row['health'];
}
else if ( $infoChanger == 3 ) {
echo $row['maxHealth'];
}
else if ( $infoChanger == 4 ) {
echo $row['gold'];
}
else if ( $infoChanger == 5 ) {
echo $row['xp'];
}
else if ( $infoChanger == 6 ) {
echo $row['xpRequire'];
}
else if ( $infoChanger == 7 ) {
echo $row['eg'];
}
}
else
{
echo "false";
}
This was my last attempt to try to do it. But it only return the value of the last one “eg”. I have it set on an a loop to call here is what I use to call it.
function recallCharInfo(user)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
while (infoChanger < 7) {
infoChanger += 1;
xmlHttp=GetXmlHttpObject();
var url="charinfo.php?user=" + user + "&changer=" + infoChanger;
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null);
}
}
I am trying to get them all to display, but just isn’t working the way and I don’t want to make a function for each one value I am trying to call. Does anyone know what is wrong with this or have I just done this wrong?
For your specific case, array indexes start at 0, so if those are all the rows in your array $row[7] will never be anything, and will always return false.
Your initial check should be:
For an alternate solution to looping:
You’re php can be:
That should return the whole row as a JSON object which you can then parse into a Javascript object in your success method with:
Then you should be able to access all your fields with