Reading rows into an array
Posted: Fri Mar 10, 2006 7:05 am
I'm using phpBB and trying to add some features to my forum. The table I am trying to read from is 'phpbb_auction_offer' and the field I would like to create the array from is 'auction_offer_title'. Bascially, 'auction_offer_title' is the title of the different auction entries.
What I am wanting to do is create an array that will read the field from 'auction_offer_title' and store it so it can be echo'd. Here is what I have so far:
This is where I'm stuck. Let's say there are 3 auctions currently in the system and they are titled "dog", "cat", and "mouse." I want to be able call up a variable that I name "current_auctions" and it'll display:
Current auctions: dog, cat, mouse
If there are only "dog" and "cat" in the database, then obviously only display those 2. I've got it figured out where it'll read the first row and display it using this code:
And this is the variable I created that I call in the phpBB template:
Basically, I'm stuck on the array part. Can anyone help?
What I am wanting to do is create an array that will read the field from 'auction_offer_title' and store it so it can be echo'd. Here is what I have so far:
Code: Select all
//set array variable
$results = array();
//talk to the db
$query = "SELECT * FROM `phpbb_auction_offer`";
$result = mysql_query($query) or die(mysql_error());
//count the rows and fields
$totalRows = mysql_num_rows($result);
$totalFields = mysql_num_fields($result);
//start the loop
for ( $i = 0; $i < $totalRows; ++$i ) {
//make it 2 dim in case you change your order
$results[$i] = mysql_fetch_array($result);Current auctions: dog, cat, mouse
If there are only "dog" and "cat" in the database, then obviously only display those 2. I've got it figured out where it'll read the first row and display it using this code:
Code: Select all
//
//Count the number of auctions
//
//select the table
$query="SELECT * FROM `phpbb_auction_offer`";
$result=mysql_query($query);
//cound the number of rows to be used later maybe
$num=mysql_numrows($result);
/gets the title of the first auction
$auction_title=mysql_result($result,$i,"auction_offer_title");
//End auction countCode: Select all
'TOTAL_AUCTIONS' => $auction_title,