Solved

Working with arrays php and mysql

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
echo button 13 47
WooCommerce Sort by Date 4 9
Jquery Autocomplete PHP script 3 21
Insert data into database 2 12
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now