I have no idea if I am doing this correctly. Eight years ago I was a C++ programmer, then I left the industry. I am lost and have been reading heaps on the web but do not know where to begin.
I wrote a MySQL DB, I have populated the DB using a PHP web page. I have put about 400 records in the DB.
I can also connect to the DB using PHP and write all the record to a web page.
My problem is I want to place one record at a time on the page. It is to help my son memorize many quotes he needs for school. I would like to be able to show one record, then when that is memorized or recalled which ever my son does. I would like to use AJAX to write the next record on the page, not appending to the last but over write the last.
Is there a way to put the PHP array into a JS array? I know I can do this.
<?
/*
* php code for loading an array to be used to load
* a JavaScript array, that will be printed to
* document.
*/
for($b=0;$b<181;$b++)
{
$a[]=$b;//loading the array '$a' using php
}
?>
<script language="javascript" type="text/javascript">
/*
* Function
* before:
* php array filled above
* js array not alive
*
* after:
* js array alive
* js array populated
* js array written to document
*/
function showValues()
{
var a=new Array;//new array
//next line is open PHP script in JavaScript function
<?
for($i=0;$i<count($a); $i++)
{
echo "a[$i]='".$a[$i]."';\n";
}
?>
//above line closes php script
document.write("This is a JavaScript array loaded from a PHP array then printed to document!<br/><br/>")
for(i=0;i<a.length;i++)
{
document.write(a[i]+' ');
if((i>0)&&(i%30==0))
{
document.write('<br/>');
}
}
}
</script>
But I am not even certain if this is the most intelligent way of doing this or if there is a smoother more intelligent way.
Is there a way that is the industry standard for capturing all the records from a MySQL DB and then using AJAX writing them on the web page as the client needs. I mean if the client only wants the first record then that is where they quit but if they read the first, second, then third and then forth they click to get to the next or previous record?