Php loop create array inside php code
I need some help with the following code...
How do I create the array from a mysql db:
I have already created the connection set: I want to get the data for my domain from the db, this I can do - My problem is mainly how to create the loop...
<?php
// Each sponsor is an element of the $sponsors array:
$sponsors = array(
array('domain1.com','The biggest social network in the world.','http://domain1.com/'),
array('domain2.com','Imaging and optical technology manufacturer.','http://domain2.com/'));
// Randomizing the order of sponsors:
shuffle($sponsors);
?>
I have tried to do it like this:
do {
array(''.$row_rs_domainrecord['g_sites_image'].'','The bigg开发者_JAVA百科est social network in the world.',''.$row_rs_domainrecord['g_sites_url'].''),
} while ($row_rs_domainrecord = mysql_fetch_assoc($rs_domainrecord)););
but get an error here
But are not getting the results and get an error $sponsors = array(
What would be the easiest way to greate this loop?
Thanks
I guess you're looking for this:
$sponsors = array();
while ($row = mysql_fetch_assoc($rs_domainrecord)) {
$sponsors[] = array($row['g_sites_image'], 'The biggest social network in the world.', $row['g_sites_url']);
}
$array[] =
appends to an existing array.
$sponser = array();
while ($row_rs_domainrecord = mysql_fetch_assoc($rs_domainrecord))
{
$sponser[] = array($row_rs_domainrecord['g_sites_image'],'The biggest social network in the world.',$row_rs_domainrecord['g_sites_url']);
}
精彩评论