Jump to content

Recommended Posts

Thank you KevinM1

 

I got this sorted and will be sending you a P.M. shortly

 

ginerjm  I don't know if you were trying to help or what and im trying my best to be a nice respectful guy but your posts are really rubbing me the wrong way and you are really coming off as insulting.  Let me just say this you can find it as hard as you want to believe or honestly please just keep on thinking im as dense as the keyboard you used to type your last reply but I can say this. If you are a magazine reader depending on what you read (If you rattled off ten or so magazines i could confirm if i did or didn't) I worked for one the largest printing companies in the US for 6 years so there's a better than average chance I worked on the database's used by the accounting department that processed the money earned from that magazine and the user database for company employees.  If you are a golfer, depending on where and what course you play on, the software used to make your tee times, process a sale in the golf department and the restaurant or had organized or gone to an event at the golf course theres a huge chance I worked on that software as well (not proud of the Event Planning section of it but what went in and out wasn't my call). The next company I worked for I hated but they did scheduling software and the company was balls to work for so I won't speak on them.

 

Last but not least depending on what hospital's, or doctor's office you go to, if you've been to the doctor's office/hospital in the last 2 years (once again depending on what affiliation's the hospital has) there is a huge possibility these ten little digits directly worked on the software used to put you into the system and the handling processing of your personal data.  Not bad for a guy struggling to get a handle on loops huh...

 

Once again you may find it hard to believe but I don't know what to tell you.

 

If you AREN'T being a dick, I have a grey bucket hat that I always wear (fishing hat as my wife calls it even though I don't fish) and i tip that hat to you in thanks for your input, you have something I want and that is knowledge of loops to better myself because I want to take over and become the guy that is responsible for updating our current parsers and creating our new one's and the idea of parsing large amounts of data is just exciting to me. If that makes me a huge nerd then so be it but i love to program and thats why I do what I do.

 

So even if you don't believe what I do or anything i've said, if you still think its impossible for me to have written anything without knowing loops, I guess we'll have to agree to disagree. I really don't want to get into an argument on the internet because I think thats just silly. Plus I don't have that kind of ego so regardless of what you might think or not think about what I do why don't we just say I work at McDonalds or 7-11 and leave that at that.  I would much rather have a new friend than an enemy.

 

Thank You!

 

JL

Link to comment
https://forums.phpfreaks.com/topic/289119-php-loops/page/2/#findComment-1484610
Share on other sites

Good morning

 

I got into the office and logged back in...

 

by the way ginerjm I actually already know how to do this:

 

while ($page = mysqli_fetch_array($query_results)
{ 
  
// call a function to do something with the current page of data
      Do_XYZ($page);
}

 

 

A while back i tough myself how to pull data and populate a table with it;  I had always used "mysqli_fetch_array" but at work most of the time we use "mysqli_fetch_assoc"  I belive fetch_array holds more information that fetch_assoc but I think I read that somewhere and don't remember.  Another interesting thing i learned was when I would pull information that way I always used the field header in SQL/MYSQL as the Key so this never came up but in the query if you put something like "SELECT * user_last_name AS lastname FROM users table"; you can make your own key.  I know thats pretty simple but it had just never come up before... anywayz I normally would do something like this (ill skip the connection information part because i have no problems with that):

 

$queryusers="SELECT * user_last_name AS lastname FROM users table";
$query_results="mysql_query($queryusers);

$row_query_results($query_results);

 

while ($page = mysqli_fetch_array($row_query_results){
echo $page['lastname'];
}
 

This is one that i would consider a little  easier... maybe im just over thinking the loop thing? I am starting to really think its more like KevinM said above; My first reaction to loops is a knee jerk "groan" and then I just start looking at a forest and not focusing on "one" individual thing.

 

Edit: i was going to put in the table tags just to show i know how to do that but decided not to as i dont have an issue with those.

Edited by jadelantern
Link to comment
https://forums.phpfreaks.com/topic/289119-php-loops/page/2/#findComment-1484678
Share on other sites

As the manual tells you (hint) MySQL_fetch_array returns what amounts to two arrays - one with associated indices and one with numeric ones.  If you don't need both of those, save resources and pick either MySQL_fetch_assoc or MySQL_fetch_row.

 

BUT OF COURSE YOU SHOULDN'T BE USING ANY THAT IS NAMED "MYSQL_*" since those functions are deprecated, slated for extinction, soon to be gone and generally frowned upon by the community in the know.

 

And from this latest post it appears that you are seeing that your problem is less with the loop than the statements being placed within it.

 

BTW - PLEASE follow the forum rules and use tags to wrap your code in.  On this forum that is the 'code' and '\code' wrapped in < and > symbols.

Edited by ginerjm
Link to comment
https://forums.phpfreaks.com/topic/289119-php-loops/page/2/#findComment-1484686
Share on other sites

  • 2 weeks later...

*Just a little update*

 

KevinM1 I think you nailed my problem last time; Wasn't able to see the forest for the trees. 

 

Ive been working with loops a lot more in my free time and the project i was giving to re-write some old parsers in our system from JavaScript to PHP have been a breeze!

 

I still need some work on deciding which loop to use where but I feel like this was a major win for me!  The first parser i re-wrote loops through and updates anywhere from 5 to 8+ thousand lines of information!

 

thank you guys so much for the help and motivation to keep going and finally knock this out of the park.

 

i'm actually working on the 2nd parser now and everything is going smooth as silk!

 

thanks again guys!

 

JL

Link to comment
https://forums.phpfreaks.com/topic/289119-php-loops/page/2/#findComment-1486140
Share on other sites

 

In PHP (and other languages), there's also foreach, which is special.  It uses an internal structure called an iterator to go through a collection (usually an array) one element at a time.  So, it always starts at the first element and ends at the last element, unless you do something like use break to end the loop prematurely.  You've seen them before, I'm sure:

$arr = array(1, '6' => 'monkey butt', 'Mississippi', 'orange' => 'is the new black');
 
foreach ($arr as $item) {
    echo $item . '<br />';
}

 

Just to add for a more complete explanation, you can also get the array key, whether it's numeric, associative, or a combination in a foreach() loop.

foreach ($arr as $arr_key => $arr_item)
{
  echo "Key: $arr_key, Item: $arr_item<br>";
}
Edited by CroNiX
  • Like 1
Link to comment
https://forums.phpfreaks.com/topic/289119-php-loops/page/2/#findComment-1486144
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.