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
Solved

Working with arrays php and mysql

Posted on 2008-10-14
2
183 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why is my wamp get_include_path() wrong? 2 21
What is wrong with this PDO Delete Query? 2 17
PHP Mail error 3 26
Ahax pagination 9 32
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

808 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