?
Solved

Working with arrays php and mysql

Posted on 2008-10-14
2
Medium Priority
?
199 Views
Last Modified: 2013-12-13
I would like to look into an array and output an array that tells me the positive or negative value of each number.

e.g.

$variables = array ( -1=>1, 9=>2, 12=>3, 0=>4);

array (-=>1, +=>2, +=>3, 0=>4)

thanks for the help
0
Comment
Question by:derekstattin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 9

Expert Comment

by:Sander Stad
ID: 22710212
Your question is al little vage. Can you be a little more precise with what you want and what you'd like to expect as a result.
0
 

Accepted Solution

by:
derekstattin earned 0 total points
ID: 22713506
Not having a great handle of programing language I am not sure how exactly to ask the question. I have been working on the code below. The code looks into an array and tells me in what period there is a negative value.  What I have been unable to figure out is how to capture these values into a new variable. In this example bayparkcapital.com/IR.php the code echos (from $number is negative) 12 is negative, 12 is negative, 12 is negative. I need to capture these 12's so I can pass them into another peice of code to get the payoff amount at a set irr.
I ask this question, becasue I am not too experienced with programing and I am trying to peice together how to achieve the desired results. I thought I could figure out a way to use get the negative/positive value of the variables in the array, then use array_count_values or array_chunk ie. Split an array into chunk before the negaive value, then count the number of variables in the array. Maybe there is a much easier way?
I had some help with the last part of the code below from mankowitz. Echo-ing $number gives me 108, the total number in the $variables array.
thanks for the help
 <?php
//connect to server
$mysqli = ();

//gather the topics
$loop_sql = "SELECT topic_id, topic_title, DATE_FORMAT(topic_create_time,  '%b %e %Y at %r') aS fmt_topic_create_time, topic_owner, INV_ID,INV_U_N, MS_F_NAME, MS_ID, CONT_DIST_1_1_08, cf_1_1_00 .... cf_12_1_08 FROM invdb ORDER BY topic_create_time DESC";
$variables = array(  'cf_12_1_08'=>1,
     'cf_11_1_08'=>2, .....
         'cf_1_1_00'=>108,
);
$loop_res = mysqli_query($mysqli, $loop_sql) or die(mysqli_error($mysqli));
echo $loop_sql;
while ($row = mysqli_fetch_assoc($loop_res)) {
foreach ($variables as $letter=>$number) {
if ($row[$letter] < 0) echo "$number is negative";
}
}
 mysqli_free_result($loop_res);
 
 //close connection to mysqli
 mysqli_close($mysqli);
?>
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question