Jump to content

Recommended Posts

Hello everyone!

 

What I am trying to achieve is probably the most basic of things but I am new to this and have been struggling to find a good explanation or at least a layman enough explanation so that I can understand it.

 

I am creating an array with several figures in. I then want to output each entry from the array, one at a time and in order of appearance, within a loop and to finish looping when the end of the array has been reached.

 

$entries = array('17957','17962','23452','45235','54345');

while($number=$entries) //some sort of loop condition
{
echo $number;
}

 

So basically it would print to screen 17957 then loop and print 17962 and so on then exit the loop once we get to the end of the array.

 

Anyhow sorry if my explanation of what I want is little shady, but any help appreciated!

 

Link to comment
https://forums.phpfreaks.com/topic/157724-indexing-through-an-array/
Share on other sites

That seems great.  :)

 

So if I use foreach under these circumstances I would have no problems?

 

<?php

$root = './';
include($root . 'con_conf.php');

$connect = mysql_connect($zdbhost, $zdbuser, $zdbpass) or die ('Database Connection Error!');

$entries = array('17957','17962');

foreach ($entries as $normalentry) {

$Nfields = "SELECT `baseattacktime`, `rangeattacktime`, `rangedattackpower`, `heroic_entry`, `unit_flags`, `lootid`, `pickpocketloot`, `equipment_id`, `MovementType` FROM `mangos`.`creature_template` WHERE `entry` = '.$normalentry.'";

$Nfieldsresult = mysql_db_query($Nfields) or die ("Failed to Gather Normal Fields");

$Nrow = mysql_fetch_row($Nfieldsresult);

$Hupdate= "UPDATE `mangos`.`creature_template` SET `baseattacktime` = '.$Nrow[0].', `rangeattacktime` = '.$Nrow[1].', `rangedattackpower` = '.$Nrow[2].', `unit_flags` = '.$Nrow[4].', `lootid` = '.$Nrow[5].', `pickpocketloot` = '.$Nrow[6].', `equipment_id` = '.$Nrow[7].', `MovementType` = '.$Nrow[8].' WHERE `heroic_entry` = '.$Nrow[3].'";

$Hupdateresult = mysql_db_query($Hupdate) or die ("Failed to Update Heroic Fields");

}

mysql_close($connect);


?>

Not exactly. You should leave out the dots, but I prefer this -

 


<?php

$root = './';
include($root . 'con_conf.php');

$connect = mysql_connect($zdbhost, $zdbuser, $zdbpass) or die ('Database Connection Error!');

$entries = array('17957','17962');

foreach ($entries as $normalentry) {

$Nfields = 'SELECT `baseattacktime`, `rangeattacktime`, `rangedattackpower`, `heroic_entry`, `unit_flags`, `lootid`, `pickpocketloot`, `equipment_id`, `MovementType` FROM `mangos`.`creature_template` WHERE `entry` = "'.$normalentry.'"';

$Nfieldsresult = mysql_db_query($Nfields) or die ('Failed to Gather Normal Fields');

$Nrow = mysql_fetch_row($Nfieldsresult);

$Hupdate= 'UPDATE `mangos`.`creature_template` SET `baseattacktime` = "'.$Nrow[0].'", `rangeattacktime` = "'.$Nrow[1].'", `rangedattackpower` = "'.$Nrow[2].'", `unit_flags` = "'.$Nrow[4].'", `lootid` = "'.$Nrow[5].'", `pickpocketloot` = "'.$Nrow[6].'", `equipment_id` = "'.$Nrow[7].'", `MovementType` = "'.$Nrow[8].'" WHERE `heroic_entry` = "'.$Nrow[3].'"';

$Hupdateresult = mysql_db_query($Hupdate) or die ('Failed to Update Heroic Fields');

}

mysql_close($connect);


?>

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.