Solved

php loops

Posted on 2013-06-12
9
178 Views
Last Modified: 2013-06-18
On the attached page I have the following recordset:
record_set('artGallery',"SELECT * FROM art_gallery WHERE artgal_Name = '$art_nme' ");

I am trying to get the following code to iterate through the array such that the "$sum_total" and "$sum_total2" produce the product of the two numbers in rows 1,2 3 etc as a list
This needs to be echoed in the body

I presume I need some type of loop ?
test.txt
0
Comment
Question by:doctorbill
  • 4
  • 3
  • 2
9 Comments
 
LVL 58

Assisted Solution

by:Gary
Gary earned 300 total points
ID: 39242122
$rows = mysql_num_rows($artGallery);

if ($rows > 0) {
	$sum_total=0;
	$sum_total2=0;

	while ($rowData = mysql_fetch_assoc($rows)) {
		$first_number = $row_artGallery[artgal_sp];
		$second_number = "2.54";
		$sum_total += $second_number * $first_number;
		$third_number = $row_artGallery[artgal_sl];
		$forth_number = "2.54";
		$sum_total2 += $forth_number * $third_number;

	}
}

print ($sum_total);
print ($sum_total2);

Open in new window

0
 

Author Comment

by:doctorbill
ID: 39242201
Is this in the top section of the page, above the head tag, or in the body where I can use echo commands ?
0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 300 total points
ID: 39242247
I don't know where you want it printing out.
0
 

Author Comment

by:doctorbill
ID: 39242315
I wanted the results echoed in the body section as a list
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 58

Accepted Solution

by:
Gary earned 300 total points
ID: 39242346
Place this in the body wherever you need it displayed

$rows = mysql_num_rows($artGallery);

if ($rows > 0) {
	while ($rowData = mysql_fetch_assoc($rows)) {
		$first_number = $row_artGallery[artgal_sp];
		$second_number = "2.54";
		$sum_total = $second_number * $first_number;
		$third_number = $row_artGallery[artgal_sl];
		$forth_number = "2.54";
		$sum_total2 = $forth_number * $third_number;
		print ($sum_total);
		print ($sum_total2); 
	}
}

Open in new window

0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 200 total points
ID: 39242707
Consider these good learning resources for PHP and MySQL.  The professional approach might be to write a query that will aggregate and sum the data.  In any case, SELECT * would not be the right approach if you can find out the names of the columns.  You would want to select by column name instead.

Beginner: Yank Ignore the hokey title -- its a good book.
Beginner to intermediate: Welling/Thompson
Intermediate to Advanced: Powers
Advanced: Zandstra
0
 

Author Comment

by:doctorbill
ID: 39243687
I am getting this:

PHP Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in I:\lbcLive\artistInfo.php on line 53
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 200 total points
ID: 39244567
That usually means your query failed and returned FALSE instead of a MySQL result resource.  This article shows how to run queries and check for success or failure.  Check the code samples - they are well-commented.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
0
 

Author Closing Comment

by:doctorbill
ID: 39255844
thanks
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

747 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

11 Experts available now in Live!

Get 1:1 Help Now