View Full Version : Array Help
evilthoutz
11-28-2011, 04:26 AM
Hello I am trying to create an array to list the results that it finds from the MySQL DB using the SELECT command.
Here is my code basically, im new to vBulletin + PHP.
$theuserid = $vbulletin->userinfo['userid'];
$result = $vbulletin->db ->query_read("SELECT * FROM vsa_advreg_invite WHERE inviter='$theuserid'");
while($row = $vbulletin->db->fetch_array){
$getcode = "You invited: " . $row['invited']. "<br> Your Code to Give: ". $row['code'] . "<br>";
}
I think you're close, you just need the while line to be
while($row = $vbulletin->db->fetch_array($result)){
evilthoutz
11-28-2011, 06:04 AM
I gave that a shot as well but still no luck. With that code it came out to be like
$theuserid = $vbulletin->userinfo['userid'];
$result = $vbulletin->db ->query_read("SELECT * FROM vsa_advreg_invite WHERE inviter='$theuserid'");
while($row = $vbulletin->db->fetch_array($result))
{
$getcode = "You invited: " . $row['invited']. "<br> Your Code to Give: ". $row['code'] . "<br>";
}
Still only showing the first result :\ I'm scratchin my head lol
Dead Eddie
11-28-2011, 11:16 AM
I gave that a shot as well but still no luck. With that code it came out to be like
$theuserid = $vbulletin->userinfo['userid'];
$result = $vbulletin->db ->query_read("SELECT * FROM vsa_advreg_invite WHERE inviter='$theuserid'");
while($row = $vbulletin->db->fetch_array($result))
{
$getcode = "You invited: " . $row['invited']. "<br> Your Code to Give: ". $row['code'] . "<br>";
}
Still only showing the first result :\ I'm scratchin my head lol
There's no way your code is going to return more than one result. Each time through the loop, you reassign the value to the same variable, deleting whatever used to be there. So, $getcode is only going to be equal to the last value it had when the loop ran.
Try this:
$getcode = '';
$theuserid = $vbulletin->userinfo['userid'];
$result = $vbulletin->db ->query_read("SELECT * FROM vsa_advreg_invite WHERE inviter='$theuserid'");
while($row = $vbulletin->db->fetch_array($result))
{
$getcode .= "You invited: " . $row['invited']. "<br> Your Code to Give: ". $row['code'] . "<br>";
}
(note the concatenation within the loop)
evilthoutz
11-28-2011, 02:00 PM
That fixed it Dead Eddie! Makes since now as to what you said ^_^ Thanks a lot!!
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.