Jump to content

Building array from database + add two standard parts


Solved_

Recommended Posts

I get a random number of database results (based on some criteria). Now I want to add two more pieces to the array, that are always the same, Key = 3 Value is "part 1" and key = 5 value = "part2", I use $number from database as KEY, that are always even numbers. Now I want to create a array that mix the pieces from the database with the two static parts. I am a bit of a beginner, how can I add two parts, without adding them multiples everytime the loop runs?

 

 

$result = mysql_query('SELECT * FROM table') or exit(mysql_error());
$number = mysql_query('SELECT * FROM table') or exit(mysql_error());

while ($row = mysql_fetch_assoc($result)) {$array[$number] = $row;}

print_r($array);  

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.