0

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 biggest 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

3
  • What's the exact error you're getting, and what exactly are you trying to do? Sorry, not clear on both counts from your question. Commented May 19, 2011 at 3:35
  • Also, ''.$row[...].'' is nonsense, it's the same as $row[...]. Commented May 19, 2011 at 3:36
  • Parse error: syntax error, unexpected T_DO, expecting ')' in C:\inetpub\wwwroot\domain\index.php on line 68 Commented May 19, 2011 at 3:38

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Deceze - The solutions works perfectly - I envisage that I am going to do this frequently and this will help alot!
2
$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']);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.