I know this is probably a newbieesque type question...but that's why im posting it here.
Im trying to roll an array from a db query. It isn't going well.
Hopefully, i have formatted the text correctly.
Thanks for help.
<?php
include 'db.php';
function test()
{
$dbhost = "*notshown*";
$dbuser = "*notshown*";
$dbpass = "*notshown*";
$dbtable = "*notshown*";
$sql = "select * from earticles where bgroup='internet'";
$db1 = new DB();
$db1->connectMysqlDB($dbhost,$dbuser,$dbpass);
$db1->selectMysqlDB($dbtable);
$results = $db1->queryMysqlDB($sql);
$numrows = mysql_num_rows($results);
$numpage = ($numrows / 3);
$x = 0;
//echo("numpage: ($numpage) numrows: ($numrows)<br>\n");
while ($row = mysql_fetch_array($results, MYSQL_ASSOC))
{
foreach ($row as $index => $value) {
$newsarray = array($index => $value);
}//end foreach
}//end while
foreach($newsarray as $index => $value) {
echo("index: ($index), value: ($value)<br>\n");
}//end foreach
}//end function test()
test();
?>
results
----------
index: (bgroup), value: (internet)
Now, the same results with a foreach statement:
==============================================
<?php
include 'db.php';
function test()
{
$dbhost = "*notshown*";
$dbuser = "*notshown*";
$dbpass = "*notshown*";
$dbtable = "*notshown*";
$sql = "select * from earticles where bgroup='internet'";
$db1 = new DB();
$db1->connectMysqlDB($dbhost,$dbuser,$dbpass);
$db1->selectMysqlDB($dbtable);
$results = $db1->queryMysqlDB($sql);
$numrows = mysql_num_rows($results);
$numpage = ($numrows / 3);
$x = 0;
//echo("numpage: ($numpage) numrows: ($numrows)<br>\n");
while ($row = mysql_fetch_array($results, MYSQL_ASSOC))
{
foreach ($row as $index => $value) {
echo("index: ($index), value: ($value)<br>\n");
}//end foreach
}//end while
}//end function test()
test();
?>
results
index: (id), value🙁3)
index: (author), value🙁Chris Gauthier)
index: (preview), value🙁Another article about NHL Hockey)
index: (full), value🙁This is the article about the bumbs who have not appreciable skills)
index: (size), value🙁2000)
index: (date), value🙁2005-02-15 11:12:11)
index: (bgroup), value🙁internet)
... to 25 more times
Can anybody help me roll this array properly? Thanks.