[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Working with arrays php and mysql

Posted on 2008-10-14
2
Medium Priority
?
204 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this article, we’ll look at how to deploy ProxySQL.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

656 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