Page 1 of 1

Select Query Help

Posted: Wed Nov 09, 2011 6:06 am
by PearlExportBen
Hi All, I have the following Query:

Code: Select all

$query = 'SELECT `BookingID`,`OfferID`, `name`, `OfferCount`,`OfferPrice` FROM `Offers_Finance` JOIN offers_details ON `OfferID` =  `o_d_id` WHERE `BookingID` ="' .$bookerid. '"';
	if ( !$result = $mysqli->query( $query ) ) { die( $mysqli->error ); } 
	$field = $result->fetch_object();

This will return anywhere between 0 and 50 Rows of Data. For Each Row returned, I want to do the following:

Code: Select all

       echo '<tr>';
       echo '<td>' . $field->name.'</td>';
       echo '<td></td>';
       echo '<td>&pound;' . $field->OfferPrice.'</td>';
       echo '<td></td>';
       echo '<td>' . $field->OfferCount . '</td>';
       echo '<td></td>';
       echo '<td>&pound;' . $field->OfferPrice * $field->OfferCount . '</td>';
       echo '</td>';
       echo '</tr>';

The problem I have is - how do I loop through the results returned from the query to output multiple rows?

Sorry if this doesn't make much snese, I'm new to PHP and the whole web development world, but have been landed with finishing a project someone else started!

If someone would be kind enough to turn this into a working example, it would help no end as I have about 20 of these things to figure out across the project!

Re: Select Query Help

Posted: Wed Nov 09, 2011 6:16 am
by social_experiment
Looping through things can be accomplished by using while, for loops.

Code: Select all

<?php
 $query = mysql_query($sql);
 
 while ($obj = mysql_fetch_object($query)) {
    echo $obj->field1;
    echo $obj->field2;
 }
?>
Hth

Re: Select Query Help

Posted: Wed Nov 09, 2011 7:44 am
by mikeashfield
Unless there are no more than 50 records in the offers_finance table then I don't see where you're limiting the results to 50 per query.