How can one display all records from Mysql database in BBcodeview ?. I don't know why BBcodeview can't display all records from MYSQL and PHP database or am i the one who is not handling it well?. I have used different approaches, but each ended up displaying only last record in bbcodeview. I used knowledge from B4Xtable, Mysql and Php, but still ended up displaying last record only. The program itself is very huge, but i have attached a simple demo consisting just three fields to demonstrate problem i am talking about. B4A, PHP, Mysql.sql and mysql.txt is in the zipped folder below to make it simpler for people to setup and handle; log(jb.GetString) and log(list1.size) show that all records were returned. I also put spinner to receive all returned record, but BBcodeview could only display last record only. Please, help me
[/CODE]
Here is the result of simple demo
Problem With BBCodeview Displaying All Record from Mysql:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private BBCodeView1 As BBCodeView
Private TextEngine As BCTextEngine
Public name, country, status As String
Private Spinner1 As Spinner
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Activity.LoadLayout("bblooptest2")
TextEngine.Initialize(Activity)
'BBCodeView1.TextEngine.WordBoundaries = "&*+-/<>=\{}" & TAB & CRLF & Chr(13)
BBCodeView1.TextEngine.WordBoundariesThatCanConnectToPrevWord = $"'.,":?;!"$
BBCodeView1.sv.ScrollViewOffsetY = 0
'This adds button to bbcodeview
Dim btn1 As Button
btn1.Initialize("btn1")
'btn2.Text = Chr(0xF04B) '"Play"
#if B4i
Btn2.InitializeCustom(btn2, xui.Color_Black, xui.Color_White)
FontSize = 12
#else
btn1.Initialize("btn1")
#End If
Dim x As B4XView = btn1
'x.Font = xui.CreateFontAwesome(28)
x.TextSize = 12
x.Text = "View Answer" 'Chr(0xF04B)
x.SetTextAlignment("CENTER","CENTER") ' i added this for alignment
x.TextColor = Colors.DarkGray
x.Color = Colors.LightGray
'btn2.SetBackgroundImage(LoadBitmapResize(File.DirAssets, "ic_wd_down_dis.png", 100%x, 100%y, True))'.Gravity = Gravity.FILL
x.SetLayoutAnimated(0, 0%x, 0, 29%x, 45dip) '(0, 0, 0, 150dip, 100dip)
BBCodeView1.Views.Put("btn1", btn1)
Dim jb As HttpJob
jb.Initialize("sch2", Me) 'https://mftp.infinityfree.net
jb.Download2("http://192.168.43.47/schphp.php", Array As String("action","sch2"))
Wait For (jb) JobDone(jb As HttpJob)
If jb.Success Then
Dim parser As JSONParser
parser.Initialize(jb.GetString)
Select jb.jobname
Case "sch2"
'let list handle parser by declaring list
Dim list1 As List
list1.Initialize
list1 = parser.NextArray 'json will extract data from json and store them as list
If list1.Size = 0 Then
MsgboxAsync("not successful", "Not Successsful")
Else
For i = 0 To list1.Size - 1
'We can now define map to hold each colum of our tables
Dim user_map As Map
user_map = list1.Get(i)
name = user_map.Get("name")
country = user_map.Get("country")
status = user_map.Get("status")
Spinner1.Add(name)
BBCodeView1.Text = _
$"[Color=#ff0000][TextSize=17][Alignment=left][b]${name}${CRLF}${country}${CRLF}${status}[/b][/Alignment][/TextSize][/Color]${CRLF}[Alignment=right][View=btn1 Vertical=10/][/Alignment]
"$
Next
End If
End Select
Else
Log("Error!")
End If
jb.Release
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Here is Php code Used (Don't worry about security issue, I have handled that in my main project):
<?php
$servername = 'localhost';
$username = 'root';
$password = '';
$dbname = 'sch';
$action = $_GET["action"];
$link = mysql_connect($servername,$username, $password) or die(mysql_error());
mysql_select_db($dbname, $link);
switch ($action)
{
case "sch2":
$sql3 = "Select * FROM sch1";
$result = mysql_query($sql3) or die(mysql_error());
$rows = array();
while ($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
print json_encode($rows);
break;
}
Mysql_close();
?>[CODE lang="b4x" title="Here is my Mysql database(just to show the problem)"]
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Database: `sch`
--
-- --------------------------------------------------------
--
-- Table structure for table `sch1`
--
CREATE TABLE `sch1` (
`name` varchar(50) NOT NULL,
`country` varchar(50) NOT NULL,
`status` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `sch1`
--
INSERT INTO `sch1` (`name`, `country`, `status`) VALUES
('University of Lagos', 'Nigeria', 'Approved'),
('Harvard University', 'USA', 'Approved'),
('MIT', 'USA', 'Approved'),
('University of Ibadan', 'Nigeria', 'Approved');
Here is the result of simple demo