I’m just getting started with databases and PHP. I’m basically building a Top Friends function but I’m running into an issue getting account numbers to be returned from the database properly. Here’s the code I’m using to test the values.
This is an include and the database connection is opened and closed in other includes.
[code=php]
<?php
$acctId = $_SESSION[“acctNum”];
$friendQuery = “SELECT * FROM friends WHERE addedById = {$acctId} OR addedId = {$acctId};”;
$result = mysql_query($friendQuery);
while($row = mysql_fetch_array($result)){
$friendAddedBy = $row[“addedById”];
$friendAdded = $row[“addedId”];
}
for($i = 0; $i < 9; $i++){
echo “AddedBy: ” . $friendAddedBy[$i] . “<br />”;
echo “Added: ” . $friendAdded[$i] . “<br />”;
}
?>
There are two records in this table, the values are:
addedById
1
1
addedId
1
571j
I tried switching addedId to varchar instead of int and threw that “j” in there to just to make sure.
The output I get is:
[code=php]
AddedBy: 1
Added: 5
AddedBy:
Added: 7
AddedBy:
Added: 1
AddedBy:
Added: j
AddedBy:
Added:
AddedBy:
Added:
AddedBy:
Added:
AddedBy:
Added:
AddedBy:
Added:
What would keep the addedId to come through in one piece. Thanks!